Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS2451: Cannot redeclare block-scoped variable 'ngDevMode'. #21925

Closed
crowmagnumb opened this issue Jan 31, 2018 · 19 comments
Closed

TS2451: Cannot redeclare block-scoped variable 'ngDevMode'. #21925

crowmagnumb opened this issue Jan 31, 2018 · 19 comments
Labels
area: core Issues related to the framework runtime freq1: low type: bug/fix
Milestone

Comments

@crowmagnumb
Copy link

crowmagnumb commented Jan 31, 2018

I'm submitting a...


[x] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

From Angular 5.1.3 and before my compilation problem worked fine. Upon upgrading to 5.2.2 I now get ...

ERROR in [at-loader] ./node_modules/@angular/core/src/render3/ng_dev_mode.d.ts:9:11
TS2451: Cannot redeclare block-scoped variable 'ngDevMode'.

ERROR in [at-loader] ../module/node_modules/@angular/core/src/render3/ng_dev_mode.d.ts:9:11
TS2451: Cannot redeclare block-scoped variable 'ngDevMode'.

This is a continuation of issue 21670 with a now working repo.

Expected behavior

No compilation error.

Minimal reproduction of the problem with instructions

Check out this repo and follow the simple instructions...

https://github.com/crowmagnumb/ng-problem

What is the motivation / use case for changing the behavior?

Broken

Environment


Angular version: 5.2.1
 
For Tooling issues:
- Node version: 8.2.1
- Platform:  Mac

Others:
@alxhub alxhub added the area: core Issues related to the framework runtime label Feb 1, 2018
@rickvandermey
Copy link

I've had the same issue, because i used our own framework as a dependency. because the versions of both repo's had different angular versions i ended up with this error. When updated both repo's to the same angular version, the error disappeared.

@mhevery mhevery added freq1: low severity3: broken regression Indicates than the issue relates to something that worked in a previous version labels Feb 6, 2018
@chuckjaz chuckjaz added type: bug/fix and removed regression Indicates than the issue relates to something that worked in a previous version labels Feb 9, 2018
@ngbot ngbot bot added this to the Backlog milestone Feb 9, 2018
@chuckjaz
Copy link
Contributor

chuckjaz commented Feb 9, 2018

The problem is fundamentally here,

"paths": {
            "Utils/*": ["../module/src/utils/*"]
        }

This causes TypeScript to bring in both the @angular/core from ../modules/node_modules/@angular/core as well as the @angular/core from ./node_modules/@angular/core. This has never been supported and errors produced in this configuration are not considered regressions as the scenario is not support, it just happened not to break for you until 5.2. There are several cases where this would have broken your code earlier, you just didn't hit them.

To state this more clearly, we don't support having two different versions of angular definitions in the same compilation.

The simple way around this is to have module and app share the same copy of angular instead of having there own. In other words, move the package.json up one directory.

If you require to have a separate compilation then I recommend using something like ng-packgr to help build the module directory as a package. This package can then be installed into the node_modules of app.

We are working to improve the ergonomics of libraries and is one of our primary focuses for this release cycle. For now, however, you need to ensure that only one copy of angular is found by the compiler or separately compile the modules using ng-packgr.

@mariohmol
Copy link

mariohmol commented Mar 3, 2018

Shouldnt this be open? cant solve it in this project https://github.com/mariohmol/ang-jsoneditor

This just works when angular/cli is 1.2.6 , with 1.7.x gives me this error

@mariohmol
Copy link

Got this working, if u get here follow this discussion 👍

#21670 (comment)

thanks

@tyholby
Copy link

tyholby commented Mar 16, 2018

I fixed it by updating my typescript dependency to "typescript": "2.5.3".
(I'm on "@angular/core": "5.2.8")

@jensenv
Copy link

jensenv commented Apr 10, 2018

I ran into this issue as well today, and tyholby's solution (upgrade typescript to 2.5.3) fixed it.

@jagomf
Copy link

jagomf commented Jun 6, 2018

Happening as well when upgrading from Angular 5.2 to 6.2

@mal90
Copy link

mal90 commented Jun 8, 2018

can confirm . this is happening in angular 6.0.3 as well.

@alexonaci
Copy link

Can confirm too. Happening also on angular 6.0.4

@maurei
Copy link

maurei commented Jun 13, 2018

Same for the following:

"@angular/cli": "~6.0.8",
"@angular/compiler-cli": "^6.0.4",

@gustavogialim
Copy link

Same for the following:

"@angular/cli": "6.0.8",
"@angular/compiler-cli": "6.0.5",

@mariohmol
Copy link

have u guys tested/checked this #21670 (comment) ?

@gustavogialim
Copy link

My personal ones worked, I had a folder of node_modules in a previous project folder, this caused the error. It was this way:

Documents / project / node_modules (Correct)
Documents / node_modules (caused the error), only deleted this folder and it worked

@maurei
Copy link

maurei commented Jun 14, 2018

Actually me it was also an error not related to angular-cli itself. I was using a custom npm library in which angular was imported. So im guessing it had to do with loading angular twice (?).

@gustavogialim
Copy link

@maurei Apparently yes, everywhere I noticed, the problem was due to two refills to the Angular, as in my case it was the duplication of the node_modules

@matheuscaldasrj
Copy link

I had an Angular Library using @angular/core 6.0.7 and when upgrade my App from Angular 5 to Angular 6 I've had this error. Looking to my package.json file I noticed that all Angular dependencies were in versions 6.0.7.

So, I changed all versions from 6.0.9 to 6.0.7 and now it works.

How is the proper way to handle with it?

@rickvandermey
Copy link

rickvandermey commented Jul 12, 2018

I've added some logic to delete all node modules from my specific library which gives the error in the 'postinstall' script:

var rmdir = require('rmdir');
var path = 'node_modules/{{ library }}/node_modules';

rmdir(path, (err, dirs, files) => {
	console.log(dirs);
	console.log('all files are removed');
});

@vimalans
Copy link

@rickvandermey, thanks it worked!

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: core Issues related to the framework runtime freq1: low type: bug/fix
Projects
None yet
Development

No branches or pull requests