Skip to content

Angular-CLI 1.5.0.rc3 + Angular 5.0.0-rc.5: Module build failed: Error: TypeScript compilation failed. #8163

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

Closed
simdevmon opened this issue Oct 24, 2017 · 15 comments
Assignees

Comments

@simdevmon
Copy link

simdevmon commented Oct 24, 2017

Bug Report or Feature Request (mark with an x)

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

Versions.

Node: 8.7.0
OS: linux x64
Angular: 5.0.0-rc.5
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.5.0-rc.3
@angular-devkit/build-optimizer: 0.0.30
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.34
@ngtools/json-schema: 1.1.0
@schematics/angular: 0.0.48
typescript: 2.3.4
webpack: 3.8.1

Repro steps.

ng new mytest
open package.json and replace all `^4.2.4` with `5.0.0-rc.5`
open package.json and set typescript version to 2.4.2
yarn install
ng build --prod

The log given by the failure.

ERROR in ./src/main.ts
Module build failed: Error: TypeScript compilation failed.
    at plugin.done.then (/var/jenkins_home/tmp/mytest2/node_modules/@angular/cli/node_modules/@ngtools/webpack/src/loader.js:479:27)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
 @ multi ./src/main.ts
ERROR in ./src/polyfills.ts
Module build failed: Error: TypeScript compilation failed.
    at plugin.done.then (/var/jenkins_home/tmp/mytest2/node_modules/@angular/cli/node_modules/@ngtools/webpack/src/loader.js:479:27)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
 @ multi ./src/polyfills.ts
ERROR in Error: TypeError: Cannot read property 'length' of undefined
    at Object.unescapeIdentifier (/var/jenkins_home/tmp/mytest2/node_modules/typescript/lib/typescript.js:10550:27)
    at getTextOfNode (/var/jenkins_home/tmp/mytest2/node_modules/typescript/lib/typescript.js:68575:27)
    at emitIdentifier (/var/jenkins_home/tmp/mytest2/node_modules/typescript/lib/typescript.js:66931:19)
    at pipelineEmitUnspecified (/var/jenkins_home/tmp/mytest2/node_modules/typescript/lib/typescript.js:66594:28)
    at pipelineEmitWithHint (/var/jenkins_home/tmp/mytest2/node_modules/typescript/lib/typescript.js:66566:50)
    at pipelineEmitWithSourceMap (/var/jenkins_home/tmp/mytest2/node_modules/typescript/lib/typescript.js:66558:17)
    at emitNodeWithComments (/var/jenkins_home/tmp/mytest2/node_modules/typescript/lib/typescript.js:64200:17)
    at pipelineEmitWithComments (/var/jenkins_home/tmp/mytest2/node_modules/typescript/lib/typescript.js:66547:17)
    at pipelineEmitWithNotification (/var/jenkins_home/tmp/mytest2/node_modules/typescript/lib/typescript.js:66541:17)
    at emit (/var/jenkins_home/tmp/mytest2/node_modules/typescript/lib/typescript.js:66528:13)
    at emitParameter (/var/jenkins_home/tmp/mytest2/node_modules/typescript/lib/typescript.js:66967:13)
    at pipelineEmitUnspecified (/var/jenkins_home/tmp/mytest2/node_modules/typescript/lib/typescript.js:66605:28)
    at pipelineEmitWithHint (/var/jenkins_home/tmp/mytest2/node_modules/typescript/lib/typescript.js:66566:50)
    at pipelineEmitWithSourceMap (/var/jenkins_home/tmp/mytest2/node_modules/typescript/lib/typescript.js:66558:17)
    at emitNodeWithComments (/var/jenkins_home/tmp/mytest2/node_modules/typescript/lib/typescript.js:64200:17)
    at pipelineEmitWithComments (/var/jenkins_home/tmp/mytest2/node_modules/typescript/lib/typescript.js:66547:17)

Desired functionality.

Successful build.

Mention any other details that might be useful.

@Stradivario
Copy link

When you try to save something inside application webpack rebuilds the application and it passes, so it is working but after a little interaction :D.

I have similar problem with 1.5.0-beta.3 and angular 5.0.0-rc.3

ERROR in TypeError: this.compiler.listLazyRoutes is not a function

@Splaktar
Copy link
Contributor

@Stradivario interesting hack, but that doesn't work for me.

I'm seeing this on:

Angular CLI: 1.5.0-rc.3
Node: 6.11.0
OS: darwin x64
Angular: 5.0.0-rc.5
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
... service-worker

@angular/cdk: 2.0.0-beta.12
@angular/cli: 1.5.0-rc.3
@angular/flex-layout: 2.0.0-beta.9-99e7450
@angular/material: 2.0.0-beta.12
@angular-devkit/build-optimizer: 0.0.31
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.34
@ngtools/json-schema: 1.1.0
@schematics/angular: 0.0.48
typescript: 2.4.2
webpack: 3.8.1

@devoto13
Copy link
Contributor

Seems to be another duplicate of the issue with multiple TypeScript versions in the project. See #5053, #8107, #8174.

You goal should be to ensure that your project has single instance of TypeScript package. Linked issues describe some workarounds how to achieve it.

@hansl hansl self-assigned this Oct 24, 2017
@hansl
Copy link
Contributor

hansl commented Oct 24, 2017

I'm looking at this right now. Not a duplicate.

@devoto13
Copy link
Contributor

devoto13 commented Oct 24, 2017

@hansl after following instructions I get two instances of typescript package. Excerpt from yarn.lock:

[email protected]:
  version "2.4.2"
  resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.4.2.tgz#f8395f85d459276067c988aa41837a8f82870844"

"typescript@>=2.0.0 <2.6.0", typescript@^2.3.3:
  version "2.5.3"
  resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.5.3.tgz#df3dcdc38f3beb800d4bc322646b04a3f6ca7f0d"

After de-duplicating it using approach I described in #8174 (comment), the error is gone. It is definitely a duplicate. There is a detailed description of what is going wrong in #8107 (comment).

These are two instances:

$ cat node_modules/typescript/package.json | grep "version"
    "version": "2.4.2",

$ cat node_modules/@angular/cli/node_modules/typescript/package.json | grep "version"
    "version": "2.5.3",

@hansl
Copy link
Contributor

hansl commented Oct 24, 2017

Okay. Even when I have 2 versions of typescript I cannot reproduce it here.

@hansl
Copy link
Contributor

hansl commented Oct 24, 2017

yarn list v1.0.2
├─ @angular-devkit/[email protected]
│  └─ [email protected]
├─ @angular/[email protected]
│  └─ [email protected]
└─ [email protected]
✨  Done in 0.69s.```

@devoto13
Copy link
Contributor

There were fixes related to peerDependencies resolution in 1.1.0 and 1.2.1. Can you try with Yarn 1.2.1? This is the version I use.

@hansl
Copy link
Contributor

hansl commented Oct 24, 2017

I'm going to keep this alive because of the discussion, but this is a duplicate of #8107 and will be closed as such when we find a solution.

@hansl
Copy link
Contributor

hansl commented Oct 24, 2017

I've been able to reproduce with Yarn 1.2.1. Here's what I get now:

$ yarn list typescript
yarn list v1.2.1
warning Filtering by arguments is deprecated. Please use the pattern option instead.
├─ @angular-devkit/[email protected]
│  └─ [email protected]
├─ @angular/[email protected]
│  └─ [email protected]
└─ [email protected]
✨  Done in 0.73s.```

@hansl
Copy link
Contributor

hansl commented Oct 24, 2017

Interestingly, the node_modules structure is different...

$ diff <(find mytest/node_modules -type d | sed 's/^mytest//') <(find mytest2/node_modules -type d | sed 's/^mytest2//')
44,46d43
< /node_modules/@angular/cli/node_modules/@ngtools/webpack/node_modules/typescript
< /node_modules/@angular/cli/node_modules/@ngtools/webpack/node_modules/typescript/bin
< /node_modules/@angular/cli/node_modules/@ngtools/webpack/node_modules/typescript/lib
255a253,254
> /node_modules/@schematics/angular/node_modules
> /node_modules/@schematics/angular/node_modules/.bin
1244a1244,1245
> /node_modules/extract-text-webpack-plugin/node_modules
> /node_modules/extract-text-webpack-plugin/node_modules/.bin
1265a1267,1268
> /node_modules/file-loader/node_modules
> /node_modules/file-loader/node_modules/.bin
2237a2241,2242
> /node_modules/less-loader/node_modules
> /node_modules/less-loader/node_modules/.bin
3053a3059
> /node_modules/sass-loader/node_modules/.bin
3327a3334,3335
> /node_modules/stylus-loader/node_modules
> /node_modules/stylus-loader/node_modules/.bin
3707a3716,3717
> /node_modules/webpack-subresource-integrity/node_modules
> /node_modules/webpack-subresource-integrity/node_modules/.bin

@hansl
Copy link
Contributor

hansl commented Oct 24, 2017

It looks like under yarn 1.2 there's no typescript package under node_modules/@angular/cli/node_modules/@ngtools/webpack/node_modules, which is probably why it works when that's there.

@devoto13
Copy link
Contributor

devoto13 commented Oct 25, 2017

I did some further investigation. And you're right, it was working in 1.0.2 exactly because Yarn was (incorrectly) putting extra typescript instance of version 2.4.2 under @ngtools/webpack. Therefore import 'typescript' was resolving to 2.4.2 in both @ngtools/webpack and @angular/compiler-cli packages.

With 1.2.1 the incorrect extra instance is gone and therefore import 'typescript' resolves to 2.5.3 in @ngtools/webpack and to 2.4.2 in @angular/compiler-cli. Since data structures are different between versions attempt to use objects created by one version inside another one leads to the exception.

So the desired fix should be to remove dependency on typescript from @angular/cli package as suggested in #8107 (comment). This ensures that there is only one instance of typescript package in the project.

@filipesilva
Copy link
Contributor

Fixed by #8185

@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 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants