angular / angular-cli

CLI tool for Angular
https://cli.angular.dev
MIT License
26.78k stars 11.98k forks source link

ng init cannot find @angular/core after update #2410

Closed FabienDehopre closed 8 years ago

FabienDehopre commented 8 years ago

Please provide us with the following information:

OS?

Windows 10

Versions.

1.0.0-beta.16

Repro steps.

Update the angular-cli from 1.0.0-beta.15 to 1.0.0-beta.16 following the update procedure in README.md

The log given by the failure.

c:\Users\f.dehopre\devs\RnD\angular2\demo-app\angular2>ng init
Cannot find module '@angular/core'
Error: Cannot find module '@angular/core'
    at Function.Module._resolveFilename (module.js:440:15)
    at Function.Module._load (module.js:388:25)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Users\f.dehopre\devs\RnD\angular2\demo-app\angular2\node_modules\@ngtools\webpack\src\plugin.js:4:14)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Users\f.dehopre\devs\RnD\angular2\demo-app\angular2\node_modules\@ngtools\webpack\src\index.js:6:10)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Users\f.dehopre\devs\RnD\angular2\demo-app\angular2\node_modules\angular-cli\models\webpack-build-typescript.js:5:17)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Users\f.dehopre\devs\RnD\angular2\demo-app\angular2\node_modules\angular-cli\models\webpack-config.js:2:34)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Users\f.dehopre\devs\RnD\angular2\demo-app\angular2\node_modules\angular-cli\tasks\build-webpack.js:6:24)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Users\f.dehopre\devs\RnD\angular2\demo-app\angular2\node_modules\angular-cli\commands\build.js:3:23)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Class.module.exports.includedCommands (C:\Users\f.dehopre\devs\RnD\angular2\demo-app\angular2\node_modules\angular-cli\addon\index.js:20:16)
    at C:\Users\f.dehopre\devs\RnD\angular2\demo-app\angular2\node_modules\angular-cli\lib\models\project.js:392:61
    at Array.forEach (native)
    at Project.addonCommands (C:\Users\f.dehopre\devs\RnD\angular2\demo-app\angular2\node_modules\angular-cli\lib\models\project.js:391:15)
    at Project.eachAddonCommand (C:\Users\f.dehopre\devs\RnD\angular2\demo-app\angular2\node_modules\angular-cli\lib\models\project.js:426:30)
    at module.exports (C:\Users\f.dehopre\devs\RnD\angular2\demo-app\angular2\node_modules\angular-cli\lib\cli\lookup-command.js:33:13)
    at CLI.<anonymous> (C:\Users\f.dehopre\devs\RnD\angular2\demo-app\angular2\node_modules\angular-cli\lib\cli\cli.js:34:26)
    at tryCatch (C:\Users\f.dehopre\devs\RnD\angular2\demo-app\angular2\node_modules\rsvp\dist\rsvp.js:538:12)
    at invokeCallback (C:\Users\f.dehopre\devs\RnD\angular2\demo-app\angular2\node_modules\rsvp\dist\rsvp.js:553:13)
    at publish (C:\Users\f.dehopre\devs\RnD\angular2\demo-app\angular2\node_modules\rsvp\dist\rsvp.js:521:7)
    at flush (C:\Users\f.dehopre\devs\RnD\angular2\demo-app\angular2\node_modules\rsvp\dist\rsvp.js:2370:5)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
jfmaeck commented 8 years ago

:+1: I am experiencing the same issue on Ubuntu Linux 16.04

boardman commented 8 years ago

Same issue on OS X 10.11.6

Bulan commented 8 years ago

Had the same, resolved with: npm install

elvirdolic commented 8 years ago

yep same issue

FabienDehopre commented 8 years ago

@Bulan npm install is a temporary workaround. ng init should work without installing npm packages manually as previous versions did.

jjstreet commented 8 years ago

I just want to add that performing ng init after npm install does not provide a list of diffs to the user. Angular-cli simply tells you:

It seems like you're using a project generated using an old version of the Angular CLI. The latest CLI now uses webpack and includes a lot of improvements, include a simpler workflow, a faster build and smaller bundles.

To get more info, including a step-by-step guide to upgrade the CLI, follow this link: https://github.com/angular/angular-cli/wiki/Upgrading-from-Beta.10-to-Beta.12

norricorp commented 8 years ago

Is this a bug that needs to be fixed? If so when will it be fixed?

filipesilva commented 8 years ago

@FabienDehopre just to confirm, did you follow the whole procedure as indicated in https://github.com/angular/angular-cli#updating-angular-cli, including deleting node_modules and doing npm install --save-dev angular-cli@latest?

npm uninstall -g angular-cli
npm cache clean
npm install -g angular-cli@latest
rm -rf node_modules dist tmp
npm install --save-dev angular-cli@latest
ng init
norricorp commented 8 years ago

Hi Filipe, yes I did all of that and then got the error message on ng init. Regards,

------ Original Message ------ From: "Filipe Silva" notifications@github.com To: "angular/angular-cli" angular-cli@noreply.github.com Cc: "norricorp" john@norricorp.f9.co.uk; "Manual" manual@noreply.github.com Sent: 09/10/2016 01:07:22 Subject: Re: [angular/angular-cli] ng init cannot find @angular/core after update (#2410)

@FabienDehopre just to confirm, did you follow the whole procedure as indicated in https://github.com/angular/angular-cli#updating-angular-cli, including deleting node_modules and doing npm install --save-dev angular-cli@latest?

npm uninstall -g angular-cli npm cache clean npm install -g angular-cli@latest rm -rf node_modules dist tmp npm install --save-dev angular-cli@latest ng init — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

FabienDehopre commented 8 years ago

@filipesilva yes, I did follow the whole update procedure. And I succeed to reproduce this issue on another project.

xtreemrage commented 8 years ago

I have the same issue when updating from .16 to .17 and yes I followed the update procedure.

angular-cli: 1.0.0-beta.17 node: 6.7.0 os: win32 x64

filipesilva commented 8 years ago

Ok, just wanted to make sure since I'm having trouble reproducing this. This is what I did:

cd beta16-project # I keep a few versions around to test stuff
rm -rf node_modules dist tmp
npm install --save-dev angular-cli@latest
ng init

And just got the normal ng init output:

kamik@T460p MINGW64 /D/sandbox/beta16-project (master)
$ ng init
installing ng2
? Overwrite .editorconfig? (Yndh)

I don't understand how it's possible to get a Error: Cannot find module '@angular/core' error on at Object.<anonymous> (C:\Users\f.dehopre\devs\RnD\angular2\demo-app\angular2\node_modules\@ngtools\webpack\src\plugin.js:4:14) since all project dependencies should have been reinstalled on npm install --save-dev angular-cli@latest.

Are you maybe using a linked global install?

I'm sorry, I'm at a loss here :/

Bulan commented 8 years ago

@filipesilva start with a beta 15 project and see maybe?

filipesilva commented 8 years ago

@Bulan for this scenario, there should be no difference between a beta.15 and a beta.17 project once you delete node_modules and the global CLI is at beta.17. Obviously there's something wrong though, so I'm asking for help.

Now I can spend 2 hours trying to repro this issue, which already has a workaround and doesn't seem to have a very big impact, trying every combination until I hit the bug. Or I can spend that time triaging and solving other issues and wait for a complete repro step that I can follow.

This repo generates a LOT of issues and it takes a long time going through all of them, so to optimize my time I tend to favor issues that I can quickly repro and debug.

Bulan commented 8 years ago

Good call, kill the big bugs first!

JanStureNielsen commented 8 years ago

See http://stackoverflow.com/questions/39780833/error-cannot-find-module-angular-core

FabienDehopre commented 8 years ago

@JanStureNielsen This is exactly that issue. I forgot to mention that I was using angular 2.0.1 instead of the 2.0.0 that angular-cli install by default. My bad :-s

elvirdolic commented 8 years ago

@JanStureNielsen This is the issue. I also upgraded angular to 2.0.1 and got this issue with ng init when updatet to beta16 and now also to beta17.

filipesilva commented 8 years ago

Great job finding the problem @JanStureNielsen! We now have either ^ or ~ for anything on @angular/* that is stable, so this shouldn't happen on upgrades again.

viewstack commented 8 years ago

I get similar errors after attempting to follow instructions to update to the latest version of angular-cli. You mentioned a workaround for this ...what would that be ?

Thanks

Cannot find module '@angular/core' Error: Cannot find module '@angular/core' at Function.Module._resolveFilename (module.js:455:15) at Function.Module._load (module.js:403:25) at Module.require (module.js:483:17) at require (internal/module.js:20:19) at Object. (/Users/ageorge/HTML5/angular-tutorial/toh/node_modules/@ngtools/webpack/src/plugin.js:5:14) at Module._compile (module.js:556:32) at Object.Module._extensions..js (module.js:565:10) at Module.load (module.js:473:32) at tryModuleLoad (module.js:432:12)npm WARN @angular/platform-server@2.1.0

On Mon, Oct 10, 2016 at 1:37 PM, Filipe Silva notifications@github.com wrote:

@Bulan https://github.com/Bulan for this scenario, there should be no difference between a beta.15 and a beta.17 project once you delete node_modules and the global CLI is at beta.17. Obviously there's something wrong though, so I'm asking for help.

Now I can spend 2 hours trying to repro this issue, which already has a workaround and doesn't seem to have a very big impact, trying every combination until I hit the bug. Or I can spend that time triaging and solving other issues and wait for a complete repro step that I can follow.

This repo generate a LOT of issues and it takes a long time going through all of them, so to optimize my time I tend to favor issues that I can quickly repro and debug.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/2410#issuecomment-252688211, or mute the thread https://github.com/notifications/unsubscribe-auth/AICCw9atXkH_5zCxI3Z-co2ZkYaFcnLjks5qynfRgaJpZM4KJrP6 .

JanStureNielsen commented 8 years ago

@viewstack -- see http://stackoverflow.com/questions/39780833/error-cannot-find-module-angular-core

jcodebrain commented 8 years ago

Exactly same issue in cli beta17

FabienDehopre commented 8 years ago

@filipesilva I thought this was now supported... but after updating the angular-cli to beta 18, I still have the same issue. Here is my package.json

{
  "name": "portal",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "start": "ng serve",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "^2.0.0",
    "@angular/compiler": "^2.0.0",
    "@angular/core": "^2.0.0",
    "@angular/forms": "^2.0.0",
    "@angular/http": "^2.0.0",
    "@angular/platform-browser": "^2.0.0",
    "@angular/platform-browser-dynamic": "^2.0.0",
    "@angular/router": "^3.0.0",
    "angular2-jwt": "^0.1.24",
    "angular2-uuid": "^1.1.0",
    "auth0-js": "^7.2.1",
    "bootstrap": "^4.0.0-alpha.5",
    "bootstrap-social": "^5.0.0",
    "core-js": "^2.4.1",
    "font-awesome": "^4.6.3",
    "moment": "^2.15.1",
    "ng2-bootstrap": "^1.1.14",
    "ng2-storever-auth": "^1.0.0-alpha.7",
    "ng2-storever-common": "^1.0.0-alpha.12",
    "rxjs": "5.0.0-beta.12",
    "simple-line-icons": "^2.4.1",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.6.23"
  },
  "devDependencies": {
    "@types/jasmine": "^2.2.30",
    "@types/node": "^6.0.42",
    "angular-cli": "^1.0.0-beta.18",
    "codelyzer": "~0.0.26",
    "jasmine-core": "2.4.1",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "4.0.9",
    "ts-node": "1.2.1",
    "tslint": "3.13.0",
    "typescript": "2.0.2"
  }
}

And the stack trace:

Cannot find module '@angular/core'
Error: Cannot find module '@angular/core'
    at Function.Module._resolveFilename (module.js:440:15)
    at Function.Module._load (module.js:388:25)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Users\f.dehopre\devs\Portal\frontend\website\node_modules\@ngtools\webpack\src\plugin.js:5:14)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Users\f.dehopre\devs\Portal\frontend\website\node_modules\@ngtools\webpack\src\index.js:6:10)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Users\f.dehopre\devs\Portal\frontend\website\node_modules\angular-cli\models\webpack-build-typescript.js:5:17)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Users\f.dehopre\devs\Portal\frontend\website\node_modules\angular-cli\models\webpack-config.js:2:34)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Users\f.dehopre\devs\Portal\frontend\website\node_modules\angular-cli\tasks\build-webpack.js:6:24)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Users\f.dehopre\devs\Portal\frontend\website\node_modules\angular-cli\commands\build.js:3:23)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Class.module.exports.includedCommands (C:\Users\f.dehopre\devs\Portal\frontend\website\node_modules\angular-cli\addon\index.js:21:16)
    at C:\Users\f.dehopre\devs\Portal\frontend\website\node_modules\angular-cli\lib\models\project.js:392:61
    at Array.forEach (native)
    at Project.addonCommands (C:\Users\f.dehopre\devs\Portal\frontend\website\node_modules\angular-cli\lib\models\project.js:391:15)
    at Project.eachAddonCommand (C:\Users\f.dehopre\devs\Portal\frontend\website\node_modules\angular-cli\lib\models\project.js:426:30)
    at module.exports (C:\Users\f.dehopre\devs\Portal\frontend\website\node_modules\angular-cli\lib\cli\lookup-command.js:33:13)
    at CLI.<anonymous> (C:\Users\f.dehopre\devs\Portal\frontend\website\node_modules\angular-cli\lib\cli\cli.js:34:26)
    at tryCatch (C:\Users\f.dehopre\devs\Portal\frontend\website\node_modules\rsvp\dist\rsvp.js:538:12)
    at invokeCallback (C:\Users\f.dehopre\devs\Portal\frontend\website\node_modules\rsvp\dist\rsvp.js:553:13)
    at publish (C:\Users\f.dehopre\devs\Portal\frontend\website\node_modules\rsvp\dist\rsvp.js:521:7)
    at flush (C:\Users\f.dehopre\devs\Portal\frontend\website\node_modules\rsvp\dist\rsvp.js:2373:5)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
filipesilva commented 8 years ago

@FabienDehopre I did some more investigation and think I know what's happening now...

Basically, when we do npm install --save-dev angular-cli@latest AND there is a difference in @angular/core versions between your project and angular-cli, we don't get node_modules/@angular/core but rather node_modules/angular-cli/node_modules/@angular/core (notice the nesting).

On the other hand, the new-ish @ngtools/webpack has a peer dependency on @angular/core - which it can't find in the top-level of node_modules/. So ng init fails.

We definitely want @ngtools/webpack to use @angular/core as a peer dependency, to ensure compatibility with the current project.

So the solution here is to update the upgrade instructions and add the extra npm install step, that wasn't needed before but now is due to @ngtools/webpack.

Thank you for the reports and pushing this issue, it was very hard to reproduce due to the @angular/core versions, which didn't always change but were commonly different in projects that were upgraded several times.

PacejetRepository commented 7 years ago

npm ERR! Windows_NT 10.0.14393 npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "cache" "clean" npm ERR! node v7.1.0 npm ERR! npm v3.10.9 npm ERR! path C:\Users\TETAY\AppData\Roaming\npm-cache npm ERR! code EPERM npm ERR! errno -4048 npm ERR! syscall rmdir

npm ERR! Error: EPERM: operation not permitted, rmdir 'C:\Users\TETAY\AppData\Roaming\npm-cache' npm ERR! { Error: EPERM: operation not permitted, rmdir 'C:\Users\TETAY\AppData\Roaming\npm-cache' npm ERR! errno: -4048, npm ERR! code: 'EPERM', npm ERR! syscall: 'rmdir', npm ERR! path: 'C:\Users\TETAY\AppData\Roaming\npm-cache' } npm ERR! npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request: npm ERR! D:\2016\Angular-2\npm-debug.log

PacejetRepository commented 7 years ago

when i tried npm cache clean the above happens

filipesilva commented 7 years ago

@PacejetRepository seems like a npm permissions thing. Try doing it again, or doing it as administrator I suppose. If you still have that error, report it to the npm issue tracker at https://github.com/npm/npm/issues.

hashemnik commented 7 years ago

Same Issue any idea to solve the problem?

equinox commented 7 years ago

@hashemnik What version of the CLI are you running?

Noting that the most recent version of the CLI no longer has the ng update/ng init commands available.

(https://github.com/angular/angular-cli/blob/master/CHANGELOG.md#breaking-changes has important updating steps for updating now).

hashemnik commented 7 years ago

@Equinox Thanks I update angular cli and it work fine.

angular-automatic-lock-bot[bot] commented 5 years ago

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.