devkit icon indicating copy to clipboard operation
devkit copied to clipboard

bug(schematics): Cannot find module '@angular-devkit/core'

Open meDavid opened this issue 9 years ago • 44 comments

Bug Report or Feature Request (mark with an x)

- [X ] bug report -> please search issues before submitting
- [ ] feature request

Area

- [ ] devkit
- [X ] schematics

Versions

node 6.9.1 npm 5.4.2 Windows 10

Repro steps

If you globally install @angular-devkit/schematics and try to create a new schematic using schematics @schematics/schematics:schematic --name=SomeSchematicName you will get the following error:

The log given by the failure

Error: Cannot find module '@angular-devkit/core'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\......\node_modules\@schematics\schematics\schematic\factory.js:10:16)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

Desired functionality

No errors and a generated new schematics blueprint

Mention any other details that might be useful

the @schematics/schematics:schematic factory uses a dependency on @angular-devkit/core, but this dependency is not in the package.json

meDavid avatar Nov 03 '17 10:11 meDavid

@MateuszStefek we're using yarn and I can't recall having any issues since switching to yarn.

The only thing is that our nightly job which tries updating the yarn lock file failed few times, but mostly it's working again the next night, or it's super easy to fix. It really is up to you to make sure that you always have the same package dependencies, that's why there are lock files, so use them

pgrm avatar Jan 19 '18 11:01 pgrm

I'd like to remind everyone that you only have reproducible installs if you use a lockfile. Both NPM v5+ and Yarn support lockfiles. If your CI works one day but not the next and you did not change your code or package.json, it is likely because one of your dependencies had a bad release and you did not have a lockfile.

It is your responsibility as a library consumer to use lockfiles. No one wants to do a release with bugs but it sometimes happens, and the best we can do is to fix it as fast as possible with a new release. When you have a couple of thousand total dependencies it is only a matter of time until one of them has a bad release.

filipesilva avatar Jan 19 '18 11:01 filipesilva

I am getting this on my local machine and my build server

Surely a package-lock file would prevent this from happening

@ediri's workaround fixed it. But probs not a long term solution

Error: Cannot find module '@angular-devkit/core'
    at Function.Module._resolveFilename (module.js:536:15)
    at Function.Module._load (module.js:466:25)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Developer\p\node_modules\@angular-devk
it\schematics\src\tree\virtual.js:10:16)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)

dolanmiu avatar Jan 19 '18 11:01 dolanmiu

Hello all,

In the package.json I have: "dependencies": { "@angular/animations": "^5.0.5", "@angular/common": "^5.0.0", "@angular/compiler": "^5.0.0", "@angular/core": "^5.0.0", "@angular/forms": "^5.0.0", "@angular/http": "^5.0.0", "@angular/platform-browser": "^5.0.0", "@angular/platform-browser-dynamic": "^5.0.0", "@angular/router": "^5.0.0", "bootstrap": "^3.3.7", "core-js": "^2.4.1", "font-awesome": "^4.7.0", "rxjs": "^5.5.2", "zone.js": "^0.8.14" }, "devDependencies": { "@angular/cli": "1.5.5", "@angular/compiler-cli": "^5.0.0", "@angular/language-service": "^5.0.0", "@types/jasmine": "~2.5.53", "@types/jasminewd2": "~2.0.2", "@types/node": "~6.0.60", "codelyzer": "^4.0.1", "jasmine-core": "~2.6.2", "jasmine-spec-reporter": "~4.1.0", "karma": "~1.7.0", "karma-chrome-launcher": "~2.1.1", "karma-cli": "~1.0.1", "karma-coverage-istanbul-reporter": "^1.2.1", "karma-jasmine": "~1.1.0", "karma-jasmine-html-reporter": "^0.2.2", "protractor": "~5.1.2", "ts-node": "~3.2.0", "tslint": "~5.7.0", "typescript": "~2.4.2" }

And I also use a lockfile package-lock.json "@angular-devkit/core": { "version": "0.0.22", "resolved": "https://registry.npmjs.org/@angular-devkit/core/-/core-0.0.22.tgz", "integrity": "sha512-zxrNtTiv60liye/GGeRMnnGgLgAWoqlMTfPLMW0D1qJ4bbrPHtme010mpxS3QL4edcDtQseyXSFCnEkuo2MrRw==", "dev": true, "requires": { "source-map": "0.5.7" } }, "@angular-devkit/schematics": { "version": "0.0.39", "resolved": "https://registry.npmjs.org/@angular-devkit/schematics/-/schematics-0.0.39.tgz", "integrity": "sha512-YoXE7mej7ARdjpiNAsg2NguIe8e3BusZRUQ7xA10AMftuPVZV2v7vV0M0j1vmH2WFEK8Tn4TqHsd5njDcvwX4g==", "dev": true, "requires": { "@angular-devkit/core": "0.0.22", "@ngtools/json-schema": "1.1.0", "minimist": "1.2.0", "rxjs": "5.5.3" }

Why am i getting this error? And how can I fix it? The only solution is to add the devkit/core as a dependency in my package.json file?

Thank you

attina-claudia avatar Jan 19 '18 12:01 attina-claudia

Please see https://github.com/angular/angular-cli/issues/9276#issuecomment-358940376 for a list of latest versions that have this problem fixed.

filipesilva avatar Jan 19 '18 12:01 filipesilva

Hi Filipe,

Thank you. So I've changed my in package.json : "devDependencies": { "@angular/cli": "1.5.6", .... }

Should I change something in the package-json.lock file? (I did not get the comment with "It is your responsibility as a library consumer to use lockfiles")

"@angular/cli": { "version": "1.5.5", "resolved": "https://registry.npmjs.org/@angular/cli/-/cli-1.5.5.tgz", "integrity": "sha512-qAooJraZwT9o2W7yx6gY6fnc7PEMlGzu60ELZJfC51MnoYMPKiIEFYeWanCSNju1P7jfpeBXuwp1qEMZCX73Zw==", "dev": true, "requires": { // don't know why is not displaying correctly the first 5 "@angular-devkit/build-optimizer": "0.0.34", //angular-devkit/build-optimize "@angular-devkit/schematics": "0.0.39", //angular-devkit/schematics "@ngtools/json-schema": "1.1.0", //ngtools/json-schema "@ngtools/webpack": "1.8.5", //ngtools/webpack "@schematics/angular": "0.1.9", //schematics/angular "autoprefixer": "6.7.7", "chalk": "2.2.2", "circular-dependency-plugin": "3.0.0", "common-tags": "1.5.1", "copy-webpack-plugin": "4.2.3", "core-object": "3.1.5", "css-loader": "0.28.7", "cssnano": "3.10.0", "denodeify": "1.2.1", "ember-cli-string-utils": "1.1.0", "exports-loader": "0.6.4", "extract-text-webpack-plugin": "3.0.0", "file-loader": "1.1.5", "fs-extra": "4.0.2", "glob": "7.1.2", "html-webpack-plugin": "2.30.1", "istanbul-instrumenter-loader": "2.0.0", "karma-source-map-support": "1.2.0", "less": "2.7.3", "less-loader": "4.0.5", "license-webpack-plugin": "1.1.1", "lodash": "4.17.4", "memory-fs": "0.4.1", "minimatch": "3.0.4", "node-modules-path": "1.0.1", "node-sass": "4.7.2", "nopt": "4.0.1", "opn": "5.1.0", "portfinder": "1.0.13", "postcss-custom-properties": "6.2.0", "postcss-loader": "2.0.9", "postcss-url": "7.3.0", "raw-loader": "0.5.1", "resolve": "1.5.0", "rxjs": "5.5.3", "sass-loader": "6.0.6", "semver": "5.4.1", "silent-error": "1.1.0", "source-map-loader": "0.2.3", "source-map-support": "0.4.18", "style-loader": "0.13.2", "stylus": "0.54.5", "stylus-loader": "3.0.1", "uglifyjs-webpack-plugin": "1.0.0", "url-loader": "0.6.2", "webpack": "3.8.1", "webpack-concat-plugin": "1.4.0", "webpack-dev-middleware": "1.12.2", "webpack-dev-server": "2.9.5", "webpack-merge": "4.1.1", "webpack-sources": "1.1.0", "webpack-subresource-integrity": "1.0.2", "zone.js": "0.8.18" }

Thank you, A.

attina-claudia avatar Jan 19 '18 13:01 attina-claudia

@attina-claudia after updating your package.json, run npm install and package-lock.json should be updated automatically.

By It is your responsibility as a library consumer to use lockfiles I mean that you, as a consumer that wants reproducible installs, must use and maintain lockfiles. No one can do it but you, and it is the only way to ensure repeated installs will yield the same dependency set.

filipesilva avatar Jan 19 '18 13:01 filipesilva

npm i --save-dev @angular-devkit/core should fix it.

This issue is related to the latest Angular cli from v1.6>

I hope this will be fixed in the upcoming Angular cli update

victorcodex avatar Jan 19 '18 17:01 victorcodex

For me, npm install @angular-devkit/core --save-dev

jonataSouza avatar Jan 19 '18 19:01 jonataSouza

In Mac, i just ran ng new my-project and then inside the project folder ng s I see the same error, I reinstall @angular/cli and ran npm install @angular-devkit/core --save-dev

cjcarvajal avatar Jan 20 '18 02:01 cjcarvajal

@My issue solve by this command: => npm i --save-dev #@angular-devkit/core => ng serve

sumitpatel19990 avatar Jan 20 '18 09:01 sumitpatel19990

This works for me npm i -D @angular-devkit/core

andreafino avatar Jan 20 '18 09:01 andreafino

You can also simply try this

npm i @angular-devkit/core

afzal00 avatar Jan 20 '18 10:01 afzal00

npm i -D @angular-devkit/core did not work , however i had to reinstall cli

prasworld avatar Jan 20 '18 19:01 prasworld

npm i --save-dev #@angular-devkit/core

by :sumitpatel19990

HammaniMourad avatar Jan 20 '18 20:01 HammaniMourad

Hi. Adding angular-devkit/core to your devDependencies is not a proper solution. As Filipe said, we need to have a lock file (package-lock.json) but make sure that you have npm v5+ (i had an older version and the lock file was ignored). If you don't have one, update angular-cli to 1.5.6. Run npm install. Should work.

attina-claudia avatar Jan 21 '18 14:01 attina-claudia

Hi, thank you very much, i have npm 5.6.0 version. cordially

2018-01-21 14:39 GMT+00:00 attina-claudia [email protected]:

Hi. Adding angular-devkit/core to your devDependencies is not a proper solution. As Filipe said, we need to have a lock file (package-lock.json) but make sure that you have npm v5+ (i had an older version and the lock file was ignored). If you don't have one, update angular-cli to 1.5.6. Run npm install. Should work.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/devkit/issues/256#issuecomment-359253093, or mute the thread https://github.com/notifications/unsubscribe-auth/AP7zhOPS78fooWFDItevCMvHa4StTUYrks5tM0wLgaJpZM4QQ58O .

-- HAMMANI Mourad Tel: 0674324902

HammaniMourad avatar Jan 21 '18 21:01 HammaniMourad

They fixed this issue at angular-cli v1.6.5 by this commit: https://github.com/angular/angular-cli/commit/c7aefaa and it works well for me without adding angular-devkit/core to my package.json. I just updated the CLI to the latest (v1.6.5) version.

merobal avatar Jan 22 '18 13:01 merobal

@theo4u thanks it worked for me npm install @angular-devkit/core --save-dev

inyee786 avatar Jan 25 '18 17:01 inyee786

This works for me ................

just run: npm i @angular-devkit/core --save

......................................................................................

piyarulps avatar Jan 30 '18 09:01 piyarulps