question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Test rebuild fail with Angular 4 and @angular/cli 1.6.5

See original GitHub issue

Versions

node v8.9.0
yarn v1.3.2
@angular/cli v1.6.2 to v1.6.5

Repro steps

  • Step 1 ng new application
  • Step 2 change in package.json angular version to v4.4.6
  • Step 3 yarn test => run fine
  • Step 4 change a spec file => error (stacktrace below)

Observed behavior

It works fine with angular 5 but not with angular 4

Stacktrace :

<!-- Normally this includes a stack trace and some more information. -->
ERROR in TypeError: Cannot read property 'length' of undefined
    at createSourceFile (/home/julien/projects/test-app/node_modules/typescript/lib/typescript.js:16640:110)
    at parseSourceFileWorker (/home/julien/projects/test-app/node_modules/typescript/lib/typescript.js:16572:26)
    at Object.parseSourceFile (/home/julien/projects/test-app/node_modules/typescript/lib/typescript.js:16521:26)
    at Object.createSourceFile (/home/julien/projects/test-app/node_modules/typescript/lib/typescript.js:16371:29)
    at new TypeScriptFileRefactor (/home/julien/projects/test-app/node_modules/@ngtools/webpack/src/refactor.js:79:35)
    at Object.findLazyRoutes (/home/julien/projects/test-app/node_modules/@ngtools/webpack/src/lazy_routes.js:18:22)
    at AotPlugin._findLazyRoutesInAst (/home/julien/projects/test-app/node_modules/@ngtools/webpack/src/plugin.js:217:50)
    at _donePromise.Promise.resolve.then.then.then.then.then (/home/julien/projects/test-app/node_modules/@ngtools/webpack/src/plugin.js:496:24)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

Same thing with --sm=false

Desired behavior

It should rebuild without error with angular 4.X.X

Mention any other details that might be useful (optional)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:22
  • Comments:40

github_iconTop GitHub Comments

9reactions
psurreycommented, Jun 23, 2018

This seems to be related to a change in the compiler_host.ts of @ngtools/webpack. See how this commit changes the invalidate function - line 177.

I fixed it by adapting the function in my node_modules (node_modules/@ngtools/webpack/src/compiler_host.js):

Original:

    invalidate(fileName) {
        fileName = this.resolve(fileName);
        if (fileName in this._files) {
            this._files[fileName] = null;
        }
        this._changedFiles[fileName] = true;
    }

Adapted:

    invalidate(fileName) {
        fileName = this.resolve(fileName);
        if (fileName in this._files) {
            this._files[fileName] = null;
            this._changedFiles[fileName] = true;
        }
    }

We have added a shell script that replaces this on npm start for every developer:

rm node_modules/@ngtools/webpack/src/compiler_host.js*
ln fixed-node-modules/compiler_host.js node_modules/@ngtools/webpack/src/compiler_host.js
6reactions
anvlkvcommented, Jan 28, 2018

@dominique-mueller in this one it works fine first time.

Second time it seems to be looking at directory instead of file…

fileName: '/Users/anvlkv/Projects/intervey/intervey-app/src'

TypeError: Cannot read property 'length' of undefined
    at createSourceFile (/Users/anvlkv/Projects/intervey/intervey-app/node_modules/typescript/lib/typescript.js:15465:109)
    at parseSourceFileWorker (/Users/anvlkv/Projects/intervey/intervey-app/node_modules/typescript/lib/typescript.js:15397:26)
    at Object.parseSourceFile (/Users/anvlkv/Projects/intervey/intervey-app/node_modules/typescript/lib/typescript.js:15346:26)
    at Object.createSourceFile (/Users/anvlkv/Projects/intervey/intervey-app/node_modules/typescript/lib/typescript.js:15195:33)
    at new TypeScriptFileRefactor (/Users/anvlkv/Projects/intervey/intervey-app/node_modules/@ngtools/webpack/src/refactor.js:79:35)
    at Object.findLazyRoutes (/Users/anvlkv/Projects/intervey/intervey-app/node_modules/@ngtools/webpack/src/lazy_routes.js:18:22)
    at AotPlugin._findLazyRoutesInAst (/Users/anvlkv/Projects/intervey/intervey-app/node_modules/@ngtools/webpack/src/plugin.js:217:50)
    at _donePromise.Promise.resolve.then.then.then.then.then (/Users/anvlkv/Projects/intervey/intervey-app/node_modules/@ngtools/webpack/src/plugin.js:496:24)
    at process._tickCallback (internal/process/next_tick.js:109:7) 
Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular CLI Error: The serve command requires to be run in ...
Angular Cli Error : The serve command requires to be run in an Angular project, but a project definition could not be found....
Read more >
CLI Overview and Command Reference - Angular
build, b. Compiles an Angular application or library into an output directory named dist/ at the given output path. ; cache. Configure persistent...
Read more >
Angular 5 Tutorial: Guide to Your First Angular 5 App - Toptal
Build a notes application from scratch for your first Angular 5 app. Learn Angular CLI, use RxJS, implement Firebase as the back-end, and...
Read more >
How To Update Angular CLI To Latest Version
After updating Angular CLI globally you might get this warning if your local project's angular cli version less than the global angular cli...
Read more >
the installed angular cli version is older than the latest stable ...
The installed Angular CLI version is older than the latest stable version. Installing a temporary version to perform the update. Installing packages for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found