Bug Report or Feature Request (mark with an x)
- [x] bug report -> please search issues before submitting
- [ ] feature request
Versions.
Globally installed:
@angular/cli: 1.4.9
node: 6.11.2
yarn: 1.2.1
os: linux x64 (Ubuntu 17.04)
node_modules of my project:
@angular/animations: 4.4.6
@angular/common: 4.4.6
@angular/compiler: 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
@angular/cli: 1.4.9
@angular/compiler-cli: 4.4.6
@angular/language-service: 4.4.6
typescript: 2.3.4
Repro steps.
- Create a new Angular project using
$ ng new my-project.
- Add any code that does not compile with TypeScript 2.5 but compiles with TypeScript 2.3 to
src/app/app.component.ts (see What's new in TypeScript for inspiration), e.g.:
interface Options {
data?: string;
timeout?: number;
maxRetries?: number;
}
function sendMessage(options: Options) {
// ...
}
const opts = {
payload: "hello world!",
retryOnFail: true,
}
// Error!
sendMessage(opts);
// No overlap between the type of 'opts' and 'Options' itself.
// Maybe we meant to use 'data'/'maxRetries' instead of 'payload'/'retryOnFail'.
- Run
$ ng serve or $ ng build --aot
The log given by the failure.
In the above setup, running $ ng serve or $ ng build --aot fails with the following error message:
ERROR in /home/simon/tech/tests/angular-deptest2/src/app/app.component.ts (19,13): Type '{ payload: string; retryOnFail: boolean; }' has no properties in common with type 'Options'.
This means that the code is getting compiled with at least TypeScript >2.4, instead of the expected version 2.3.4 (as per my project's package.json – which angular-cli generated).
Desired functionality.
The code should compile (JIT and AOT) as my project's package.json lists "typescript": "~2.3.3" as a dependency.
Mention any other details that might be useful.
yarn link lists the following dependencies for angular-cli:
yarn list v1.2.1
…
├─ @angular/cli@1.4.9
…
│ ├─ typescript@>=2.0.0 <2.6.0
│ ├─ typescript@2.5.3
…
├─ typescript@2.3.4
and, indeed:
$ cat node_modules/@angular/cli/node_modules/typescript/package.json | grep version
"version": "2.5.3",
confirming that TypeScript 2.5.3 was installed (which is probably because of angular-cli's chalk dependency which depends precisely on TypeScript 2.5.3 or higher). Now, I suspect that @ngtools/webpack – which angular-cli uses for compiling – will simply take its sibling TypeScript node module for compilation. So since it's also being installed to node_modules/@angular/cli/node_modules/, it will use the TypeScript version in node_modules/@angular/cli/node_modules/typescript (i.e. 2.5.3), not node_modules/typescript (which is v2.3.4).
Temporary workaround.
Add @ngtools/webpack as a dev dependency to your Angular project's package.json. Afterwards remove the node_modules folder and the yarn.lock file and resolve all dependencies from scratch using $ yarn install. @ngtools/webpack will then be installed to node_modules/@ngtools/webpack and should thus find the TypeScript version in node_modules/typescript.
Bug Report or Feature Request (mark with an
x)Versions.
Repro steps.
$ ng new my-project.src/app/app.component.ts(see What's new in TypeScript for inspiration), e.g.:$ ng serveor$ ng build --aotThe log given by the failure.
In the above setup, running
$ ng serveor$ ng build --aotfails with the following error message:This means that the code is getting compiled with at least TypeScript >2.4, instead of the expected version 2.3.4 (as per my project's
package.json– which angular-cli generated).Desired functionality.
The code should compile (JIT and AOT) as my project's package.json lists
"typescript": "~2.3.3"as a dependency.Mention any other details that might be useful.
yarn linklists the following dependencies forangular-cli:and, indeed:
confirming that TypeScript 2.5.3 was installed (which is probably because of angular-cli's
chalkdependency which depends precisely on TypeScript 2.5.3 or higher). Now, I suspect that@ngtools/webpack– which angular-cli uses for compiling – will simply take its sibling TypeScript node module for compilation. So since it's also being installed tonode_modules/@angular/cli/node_modules/, it will use the TypeScript version innode_modules/@angular/cli/node_modules/typescript(i.e. 2.5.3), notnode_modules/typescript(which is v2.3.4).Temporary workaround.
Add
@ngtools/webpackas a dev dependency to your Angular project'spackage.json. Afterwards remove thenode_modulesfolder and theyarn.lockfile and resolve all dependencies from scratch using$ yarn install.@ngtools/webpackwill then be installed tonode_modules/@ngtools/webpackand should thus find the TypeScript version innode_modules/typescript.