Versions of @angular/compiler-cli and typescript could not be determined.
Bug Report or Feature Request (mark with an x)
- [x] bug report -> please search issues before submitting
- [ ] feature request
Versions.
ng 1.5.0 node 8.9.0 npm 5.5.1 yarn 1.3.2 visual studio code 1.17.2
Repro steps.
run ng serve or ng serve -aot
The log given by the failure.
Versions of @angular/compiler-cli and typescript could not be determined. The most common reason for this is a broken npm install.
Please make sure your package.json contains both @angular/compiler-cli and typescript in devDependencies, then delete node_modules and package-lock.json (if you have one) and run npm install again.
Desired functionality.
Mention any other details that might be useful.
here my package.json
{
"name": "migate",
"version": "0.1.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^5.0.0",
"@angular/common": "^5.0.0",
"@angular/core": "^5.0.0",
"@angular/forms": "^5.0.0",
"@angular/platform-browser": "^5.0.0",
"@angular/platform-browser-dynamic": "^5.0.0",
"@angular/router": "^5.0.0",
"bootstrap": "^4.0.0-beta.2",
"core-js": "^2.5.1",
"global": "^4.3.2",
"jquery": "^3.2.1",
"json-typescript-mapper": "^1.1.3",
"popper.js": "^1.12.6",
"roboto-fontface": "^0.8.0",
"rxjs": "^5.5.2",
"typescript-string-operations-ng4": "^0.1.0",
"zone.js": "^0.8.18"
},
"devDependencies": {
"@angular/cli": "^1.5.0",
"@angular/compiler": "^5.0.0",
"@angular/compiler-cli": "^5.0.0",
"@angular/language-service": "^5.0.0",
"@types/jasmine": "~2.6.2",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.0.47",
"codelyzer": "~4.0.0",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.3.0",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.2.0",
"ts-node": "~3.3.0",
"tslint": "~5.8.0",
"typescript": "~2.4.0",
"webpack": "^3.8.1",
"webpack-sources": "^1.0.1"
}
}
please read my solution above and try it. it may help you
@frigel : thanks, NODE_ENV was the issue.
The above solutions did not work for me. If you are still having issues like I did, try this:
npm install --save
This will put the latest version of the module into your package.json
for example, I ran npm install --save @angular/cli @angular/compiler-cli to get the latest version of those two modules and got the version 4.4.6 for the @angular/compiler-cli. Then I changed all other @angular dependencies (minus the @angular/cli one) to be the same. So my package.json looks like this:
{
"name": "mean-contactlist-angular2",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "node server.js",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postinstall": "ng build"
},
"private": true,
"dependencies": {
"@angular/cli": "^1.0.2",
"@angular/common": "^4.4.6",
"@angular/compiler": "^4.4.6",
"@angular/compiler-cli": "^4.4.6",
"@angular/core": "^4.4.6",
"@angular/forms": "^4.4.6",
"@angular/http": "^4.4.6",
"@angular/platform-browser": "^4.4.6",
"@angular/platform-browser-dynamic": "^4.4.6",
"@angular/router": "^4.4.6",
"body-parser": "^1.17.1",
"core-js": "^2.4.1",
"express": "^4.15.2",
"mongodb": "^2.2.26",
"rxjs": "^5.1.0",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@types/jasmine": "2.5.38",
"@types/node": "~6.0.60",
"codelyzer": "~2.0.0",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.2.0",
"karma": "~1.4.1",
"karma-chrome-launcher": "~2.0.0",
"karma-cli": "~1.0.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-coverage-istanbul-reporter": "^0.2.0",
"protractor": "~5.1.0",
"ts-node": "~2.0.0",
"tslint": "~4.5.0",
"typescript": "~2.2.0"
}
}
ran npm install again, and it builds fine.
Closing as there seem to be suggestion to address the problem.
This problem seems to depend on your environment. If you are running npm in production mode (npm install --prod or if you have NODE_ENV=production somewhere), then only dependencies in your package.json will be installed. The packages in devDependencies will not be installed.
But many packages in devDependencies are needed to build your app. So you either don't install in prod mode, or move the needed devDependencies over to dependencies.
In my case, the "dev-dependencies" were not installed when I executed npm install. (I was surprised how quickly the modules have been installed :| )
Probably the file package-lock.json prevented the installation of the development dependencies.
Solution 1, as suggested in the above answers, would be to delete the directory: node_modules and the file: package-lock.json. Afterwards, perform a clean installation: npm install
Solution 2, suggested on StackOverflow would be to force the installation of dev-dependencies by running: npm install --dev OR npm install --only=dev
typescript 2.4 solved it for me
I had this problem, and it was solved by adding @angular/compiler to devDepenendencies.
god bless you @sudhakar216. why is typescript required to be in the dependencies when before i only had to have it in devDependencies? however i was only having this issue trying to run ng build on my heroku server
Heroku doesn’t install dev dependencies.
interesting, ive ran ng build many times on heroku servers before with typescript only in the devDependencies but thats ok at least its working now
I've tried all solutions provided above and I'm still encountering this issue. Running node v9.4.0 and npm v5.6.0.
Here is my package.json file:
"dependencies": {
"@angular/cli": "^1.6.6",
"@angular/common": "~4.0.0",
"@angular/compiler": "~4.0.0",
"@angular/compiler-cli": "^5.2.2",
"@angular/forms": "~4.0.0",
"@angular/http": "~4.0.0",
"@angular/platform-browser": "~4.0.0",
"@angular/platform-browser-dynamic": "~4.0.0",
"@angular/router": "~4.0.0",
"angular-in-memory-web-api": "~0.3.0",
"systemjs": "0.19.40",
"core-js": "^2.4.1",
"rxjs": "5.0.1",
"typescript": "^2.1.6",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/cli": "^1.6.6",
"@angular/compiler": "~4.0.0",
"@angular/compiler-cli": "^5.2.2",
"@angular/core": "^4.0.3",
"@types/jasmine": "2.5.36",
"@types/node": "^6.0.46",
"canonical-path": "0.0.2",
"concurrently": "^3.2.0",
"jasmine-core": "~2.4.1",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-jasmine-html-reporter": "^0.2.2",
"lite-server": "^2.2.2",
"lodash": "^4.16.4",
"protractor": "~4.0.14",
"rimraf": "^2.5.4",
"tslint": "^3.15.1",
"typescript": "^2.1.6"
},
I've tried running NODE_ENV=development npm install and npm install --dev with no luck. I've dumped the node_modules directory and package-lock.json each time.
I've also had the same problem, and nothing of the above worked. For me it was the wrong version of "@angular/cli": "^1.5.0" dependent on wrong version of "@angular/compiler-cli": "^5.0.0". What i did was to set latest versions for all packages and delete npm-shrinkwrap.json. (I also needed to install "@angular-devkit/core","@angular-devkit/schematics"and "@schematics/angular"). My package.json looks like this, and it works now:
"dependencies": {
"@angular-devkit/schematics": "^0.3.1",
"@angular/animations": "^5.0.0",
"@angular/cdk": "^5.2.0",
"@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/material": "^5.2.0",
"@angular/platform-browser": "^5.0.0",
"@angular/platform-browser-dynamic": "^5.0.0",
"@angular/router": "^5.0.0",
"@schematics/angular": "^0.3.1",
"core-js": "^2.4.1",
"rxjs": "^5.5.2",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "^1.6.8",
"@angular/compiler-cli": "^5.0.0",
"@angular/language-service": "^5.0.0",
"@angular-devkit/core": "^0.3.1",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "^4.1.0",
"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"
}
{
"name": "bookstore",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"start": "node server.js",
"build": "ng build --prod",
"ng": "ng",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postinstall": "ng build --prod"
},
"private": true,
"dependencies": {
"@agm/core": "^1.0.0-beta.2",
"@angular-devkit/core": "0.0.28",
"@angular/animations": "^5.2.4",
"@angular/cli": "^1.5.2",
"@angular/common": "~2.2.0",
"@angular/compiler": "~2.2.0",
"@angular/core": "^5.2.4",
"@angular/forms": "~2.2.0",
"@angular/http": "~2.2.0",
"@angular/platform-browser": "^2.4.10",
"@angular/platform-browser-dynamic": "^2.4.10",
"@angular/router": "^3.4.10",
"@types/jquery": "^3.3.0",
"body-parser": "^1.18.2",
"bxslider": "^4.2.13",
"chart.js": "^2.5.0",
"core-js": "^2.4.1",
"cors": "2.8.1",
"express": "^4.16.2",
"font-awesome": "^4.7.0",
"hammerjs": "^2.0.8",
"iconv-lite": "^0.4.19",
"jquery": "^3.3.1",
"method-override": "~2.1.2",
"mongoose": "^4.13.11",
"nodemon": "^1.14.11",
"rxjs": "^5.5.2",
"typescript": "^2.7.1",
"zone.js": "^0.8.19"
},
"engines": {
"node": "6.11.0",
"npm": "3.10.10"
},
"devDependencies": {
"@angular/compiler-cli": "^5.2.4",
"@angular/forms": "^2.2.0",
"@angular/language-service": "^5.2.4",
"@types/jasmine": "~2.8.3",
"@types/jasminewd2": "~2.0.2",
"@types/node": "^6.0.100",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"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",
"rxjs": "^5.5.0",
"ts-node": "~3.2.0",
"tslint": "~5.9.1",
"typescript": "^2.7.1",
"zone.js": "^0.8.4"
}
}
Same with me. I am trying to setup Angular 2 project.
@evanchime advice is good for deploying to heroku, thanks
I changed TypeScript version to "typescript": "^2.0.2", and error is gone.
However, I see a warning everytime I deploy to Heroku:
@angular/[email protected] requires typescript@'>=2.0.2 <2.3.0' but 2.5.3 was found instead. Using this version can result in undefined behaviour and difficult to debug problems.
It looks that some packages not installed.
I was facing the same error when running npm install from Git Bash.
But after running it in Command Prompt the error has gone.
So remove node_modules and package-lock.json, and use Command Prompt to perform npm install and to serve the application after that.
I've tried all the ways posted here, but no luck. But it was solved after I tried 'npm install -g npm@latest'.
Solved just by running npm i --only=dev for me. Looks like devDependencies dont always install with npm i.
Ok, i know this is a closed issue but because neither of the above solutions worked for me, i am posting my solution in case someone needs it.
But first things first as i think that this error can occur for many different reasons.
ng build --prod was throwing the error mentioned in the post title.
At that point, ng version gives the following:
Angular CLI: 6.0.3 Node: 10.0.0 OS: linux x64 Angular: 6.0.2 ... animations, common, compiler, compiler-cli, core, forms ... http, language-service, platform-browser ... platform-browser-dynamic, router
Package Version
@angular-devkit/architect 0.6.3 (cli-only)
@angular-devkit/build-angular 0.6.3
@angular-devkit/core 0.6.3 (cli-only)
@angular-devkit/schematics 0.6.3 (cli-only)
@angular/cli 6.0.3
@schematics/angular 0.6.3 (cli-only)
@schematics/update 0.6.3 (cli-only)
rxjs 6.1.0
typescript 2.7.2
And my pachage.json was like that:
{
"name": "Test",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.0.2",
"@angular/common": "^6.0.2",
"@angular/compiler": "^6.0.2",
"@angular/core": "^6.0.2",
"@angular/forms": "^6.0.2",
"@angular/http": "^6.0.2",
"@angular/platform-browser": "^6.0.2",
"@angular/platform-browser-dynamic": "^6.0.2",
"@angular/router": "^6.0.2",
"core-js": "^2.5.6",
"rxjs": "^6.1.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/compiler-cli": "^6.0.2",
"@angular-devkit/build-angular": "~0.6.3",
"typescript": "~2.7.2",
"@angular/cli": "~6.0.3",
"@angular/language-service": "^6.0.2",
"@types/jasmine": "~2.8.7",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~10.1.2",
"codelyzer": "~4.3.0",
"jasmine-core": "~3.1.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.2",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^1.1.0",
"protractor": "~5.3.2",
"tslint": "~5.10.0",
}
}
All the above was autogenerated by ng new.
And the build log:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node',
1 verbose cli '/usr/local/lib/node_modules/npm/bin/npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'build',
1 verbose cli '--scripts-prepend-node-path=auto' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle [email protected]~prebuild: [email protected]
6 info lifecycle [email protected]~build: [email protected]
7 verbose lifecycle [email protected]~build: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~build: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/etc/apache2/htdocs/earth-zero.com/admin/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
9 verbose lifecycle [email protected]~build: CWD: /etc/apache2/htdocs/earth-zero.com/admin
10 silly lifecycle [email protected]~build: Args: [ '-c', 'ng build' ]
11 silly lifecycle [email protected]~build: Returned: code: 2 signal: null
12 info lifecycle [email protected]~build: Failed to exec build script
13 verbose stack Error: [email protected] build: `ng build`
13 verbose stack Exit status 2
13 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:283:16)
13 verbose stack at EventEmitter.emit (events.js:182:13)
13 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:182:13)
13 verbose stack at maybeClose (internal/child_process.js:947:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:236:5)
14 verbose pkgid [email protected]
15 verbose cwd /etc/apache2/htdocs/earth-zero.com/admin
16 verbose Linux 4.13.0-41-generic
17 verbose argv "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/bin/npm-cli.js" "run" "build" "--scripts-prepend-node-path=auto"
18 verbose node v10.0.0
19 verbose npm v6.0.1
20 error code ELIFECYCLE
21 error errno 2
22 error [email protected] build: `ng build`
22 error Exit status 2
23 error Failed at the [email protected] build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 2, true ]
So after two days of googling and reading and going all over the same answers again and again, i decided to get the error line by line
Versions of @angular/compiler-cli and typescript could not be determined.
Either i did not installed the compiler-cli and typescript ( which i did, believe me, i checked many times ) either i had a buggy version of them.
Next question was what triggers the problem?
The issue comes from the execution of the ng program with some parameters. If we execute ng serve we get the same error so the error itself does not come from the parameters but from within ng. It is narrowed down to the ng executable.
I dive into the node_modules directory and from there to the angular-cli.
With a recursive grep
grep -R "Versions of @angular/compiler-cli and typescript could not be determined." .
i get this:
./upgrade/version.js: Versions of @angular/compiler-cli and typescript could not be determined.
Well hello, my friend.
The vesion.js at some point try to load the compiler-cli and typescript:
try {
compilerVersion = require_project_module_1.requireProjectModule(projectRoot, '@angular/compiler-cli').VERSION.full;
tsVersion = require_project_module_1.requireProjectModule(projectRoot, 'typescript').version;
}
catch (_a) {
console.error(core_1.terminal.bold(core_1.terminal.red(core_1.tags.stripIndents `
Versions of @angular/compiler-cli and typescript could not be determined.
The most common reason for this is a broken npm install.
Please make sure your package.json contains both @angular/compiler-cli and typescript in
devDependencies, then delete node_modules and package-lock.json (if you have one) and run npm install again.
`)));
process.exit(2);
}
With a console.log inside try block i know that the ng reaches the try block and then throw an error. I take the first candidate 'compiler-cli', and open index.js inside node modules. At some point, the index has this little guy var tslib_1 = require("tslib");
Lazy debugging and i get Before but no after.
console.log( 'Before' );
var tslib_1 = require("tslib");
console.log( 'After' );
A quick search to the compiler-cli package.json reveal that tslib is missing. Added to my package.json with some other missing dependencies which are irrelevant to the issue
{
"name": "Test",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.0.2",
"@angular/common": "^6.0.2",
"@angular/compiler": "^6.0.2",
"@angular/core": "^6.0.2",
"@angular/forms": "^6.0.2",
"@angular/http": "^6.0.2",
"@angular/platform-browser": "^6.0.2",
"@angular/platform-browser-dynamic": "^6.0.2",
"@angular/router": "^6.0.2",
"core-js": "^2.5.6",
"rxjs": "^6.1.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/compiler-cli": "^6.0.2",
"@angular-devkit/build-angular": "~0.6.3",
"@angular-devkit/build-optimizer": "^0.6.3",
"typescript": "~2.7.2",
"@angular/cli": "~6.0.3",
"@angular/language-service": "^6.0.2",
"@types/jasmine": "~2.8.7",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~10.1.2",
"codelyzer": "~4.3.0",
"jasmine-core": "~3.1.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.2",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^1.1.0",
"protractor": "~5.3.2",
"semver": "^5.5.0",
"tslint": "~5.10.0",
"tslib": "^1.9.1",
"webpack": "^4.8.3"
}
}
And voila ng build --prod working like a charm.
The final questions
Is this a fix or a workaround because i am missing the big picture? Is tslis a missing dependency from compiler-cli which needs to be included in a later version or do we have to include it in our package json?
I hope to save some time from the next one who will fall into this problem.
P.S Sorry for my bad English.
Better solution for my answer. Solve all future angular installations.
npm install -g tslib
Or with root privileges
sudo npm install -g tslib