Angular-cli: linter with YARN => TypeError: Cannot read property '' of undefined / Allocation failed - JavaScript heap out of memory

Created on 24 May 2018  路  14Comments  路  Source: angular/angular-cli

Hi

I have these scripts:

"lint:check": "ng run paul:lint --type-check"
"lint:fix": "yarn-or-npm run lint:check -- --fix"

But when I run lint:check, I get these errors:

The 'curly' rule threw an error in 'C:/Users/AAA/Documents/projets/paul/paul-cs/src/app/shared/helper
TypeError: Cannot read property 'pos' of undefined

The 'no-string-throw' rule threw an error in 'C:/Users/AAA/Documents/projets/paul/paul-cs/src/app/sha
TypeError: Cannot read property 'kind' of undefined

The 'no-arg' rule threw an error in 'C:/Users/AAA/Documents/projets/paul/paul-cs/src/app/shared/state         
TypeError: Cannot read property 'text' of undefined                                                               

<--- Last few GCs --->                                                                                            

[12280:0000000000458B60]    14500 ms: Mark-sweep 705.1 (754.5) -> 705.0 (754.5) MB, 362.5 / 0.0 ms  alloc         
[12280:0000000000458B60]    14945 ms: Mark-sweep 705.0 (754.5) -> 704.9 (714.5) MB, 444.7 / 0.0 ms  last          
[12280:0000000000458B60]    15333 ms: Mark-sweep 704.9 (714.5) -> 704.9 (714.5) MB, 388.1 / 0.0 ms  last          

<--- JS stacktrace --->                                                                                                                                                                                                
==== JS stack trace =========================================                                                                                                                                                              
Security context: 000002DDA35257C1 <JSObject>                                                                     
    1: _loop_1(aka _loop_1) [C:\Users\AAA\Documents\projets\paul\paul-cs\node_modules\tslint\lib\rule         
 <undefined>,identifier=000000F7F0DEE979 <IdentifierObject map = 000002EDAEEC6C49>)                               
    2: /* anonymous */(aka /* anonymous */) [C:\Users\AAA\Documents\projets\paul\paul-cs\node_modules         

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory                                
 1: node_module_register                                                                                          
 2: v8::internal::FatalProcessOutOfMemory                                                                         
 3: v8::internal::FatalProcessOutOfMemory                                                                         
 4: v8::internal::Factory::NewUninitializedFixedArray                                                             
 5: v8::internal::WasmDebugInfo::SetupForTesting                                                                  
 6: v8::internal::interpreter::BytecodeArrayRandomIterator::UpdateOffsetFromIndex                                 
 7: 000000BFF98843C1                                                                                              
error Command failed with exit code 3.

Angular 6.0.3
Material: 6.0.3
CDK: 6.1.0
OS: Windows 7 64 bits pro
TypeScript: 2.7.2
NodeJS: 8.11.1

Any idea why ?

Thank you in advance

Regards

Edit: thanks to @miikaah, it's seems it's an issue related to yarn.
Workaround: Install dependencies with NPM instead of YARN

devkibuild-angular repro steps

Most helpful comment

To reproduce, do the following:

ng new testapp
cd testapp
ng lint

So far, it should work.

Add this package.json:

{
  "name": "todo",
  "version": "0.0.4",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "build:prod": "ng build --prod -d assets/",
    "test": "ng test",
    "test:coverage": "ng test --single-run --code-coverage",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular-redux/router": "^9.0.0",
    "@angular-redux/store": "^9.0.0",
    "@angular/animations": "^6.0.4",
    "@angular/common": "^6.0.4",
    "@angular/compiler": "^6.0.4",
    "@angular/core": "^6.0.4",
    "@angular/forms": "^6.0.4",
    "@angular/http": "^6.0.4",
    "@angular/platform-browser": "^6.0.4",
    "@angular/platform-browser-dynamic": "^6.0.4",
    "@angular/router": "^6.0.4",
    "@ng-bootstrap/ng-bootstrap": "^2.0.0",
    "bootstrap": "^4.1.1",
    "class-validator": "^0.8.1",
    "core-js": "^2.4.1",
    "graphql-request": "^1.4.1",
    "lodash-es": "^4.17.4",
    "mobile-drag-drop": "^2.3.0-rc.1",
    "redux": "^4.0.0",
    "redux-logger": "^3.0.6",
    "redux-observable": "^1.0.0-beta.1",
    "rxjs": "^6.2.0",
    "rxjs-tslint": "^0.1.4",
    "web-animations-js": "^2.3.1",
    "zone.js": "^0.8.19"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.6.8",
    "@angular/cli": "^6.0.8",
    "@angular/compiler-cli": "^6.0.4",
    "@angular/language-service": "^6.0.4",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~9.4.6",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.0",
    "tslint": "~5.9.1",
    "typescript": "~2.7.2"
  }
}

Run:

yarn install
ng lint

This should throw the TypeError: Cannot read property 'xyz' of undefined errors which probably lead to the out of memory errors on bigger projects.

Running

rm -rf node_modules
npm install

fixes the problem for me too, so this might actually be a yarn problem.

All 14 comments

This seems like a bug but we'll need to look at a reproduction to find and fix the problem. Can you setup a minimal repro please?

You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

@filipesilva

Unfortunately, this issue appears on a private project available only into the company where I'm working so I can't share the data / code etc, unless you know what snippet you want exactly and I can try to extract it from the project.

But I have no idea for the moment how to reproduce the problem.

It's not simple, like an issue angular with material etc.
I m feel powerless against this issue :/

I will try to reproduce it with the same computer, the next week with some tests to understand if it's node or something else which can be guilty

If you are using yarn to install your packages try using npm instead. We just had this problem in two enterprise projects when we upgraded from angular v5 to v6 and managed to fix it by switching from yarn to npm.
rm -rf node_modules
npm install
ng lint

@miikaah , yeah thank you, it's working using npm to install dependancies and after that I can use yarn :)

Hi,

Same Issue Here; any help is appreciate;

btw,
installing packages via npm works for me

To reproduce, do the following:

ng new testapp
cd testapp
ng lint

So far, it should work.

Add this package.json:

{
  "name": "todo",
  "version": "0.0.4",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "build:prod": "ng build --prod -d assets/",
    "test": "ng test",
    "test:coverage": "ng test --single-run --code-coverage",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular-redux/router": "^9.0.0",
    "@angular-redux/store": "^9.0.0",
    "@angular/animations": "^6.0.4",
    "@angular/common": "^6.0.4",
    "@angular/compiler": "^6.0.4",
    "@angular/core": "^6.0.4",
    "@angular/forms": "^6.0.4",
    "@angular/http": "^6.0.4",
    "@angular/platform-browser": "^6.0.4",
    "@angular/platform-browser-dynamic": "^6.0.4",
    "@angular/router": "^6.0.4",
    "@ng-bootstrap/ng-bootstrap": "^2.0.0",
    "bootstrap": "^4.1.1",
    "class-validator": "^0.8.1",
    "core-js": "^2.4.1",
    "graphql-request": "^1.4.1",
    "lodash-es": "^4.17.4",
    "mobile-drag-drop": "^2.3.0-rc.1",
    "redux": "^4.0.0",
    "redux-logger": "^3.0.6",
    "redux-observable": "^1.0.0-beta.1",
    "rxjs": "^6.2.0",
    "rxjs-tslint": "^0.1.4",
    "web-animations-js": "^2.3.1",
    "zone.js": "^0.8.19"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.6.8",
    "@angular/cli": "^6.0.8",
    "@angular/compiler-cli": "^6.0.4",
    "@angular/language-service": "^6.0.4",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~9.4.6",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.0",
    "tslint": "~5.9.1",
    "typescript": "~2.7.2"
  }
}

Run:

yarn install
ng lint

This should throw the TypeError: Cannot read property 'xyz' of undefined errors which probably lead to the out of memory errors on bigger projects.

Running

rm -rf node_modules
npm install

fixes the problem for me too, so this might actually be a yarn problem.

I just tried with [email protected] and the following dependencies:

    "@angular-devkit/build-angular": "~0.7.0-rc.0",
    "@angular/cli": "~6.1.0-rc.0",

And I did not get the error you are seeing. This is the output I got:

kamik@RED-X1C6 MINGW64 /d/sandbox/latest-project (master)
$ rm -rf node_modules/ && yarn && ng lint
yarn install v1.5.1
info No lockfile found.
[1/4] Resolving packages...
warning karma-coverage-istanbul-reporter > istanbul-api > [email protected]: 1.2.0 should have been a major version bump
[2/4] Fetching packages...
info [email protected]: The platform "win32" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
warning Your current version of Yarn is out of date. The latest version is "1.7.0", while you're on "1.5.1".
info To upgrade, download the latest installer at "https://yarnpkg.com/latest.msi".
Done in 251.62s.


All files pass linting.


All files pass linting.

Do you still get the TypeError: Cannot read property 'xyz' of undefined error with the versions I used? What version of yarn are you on?

I am using [email protected] and I encounter same error. Switching to NPM can avoid it, but I need yarn to hoist dependencies in my monorepo with Lerna.

This issue does not exist anymore in the newer angular 7.

"@angular-devkit/build-angular": "~0.10.6",
"@angular/cli": "^7.0.6",
"@angular/__anything else__": "^7.0.4",
yarn 1.7.0

I found a workaround for this issue which is probably caused by this Yarn's issue

I add this script to Angular project package.json

"postinstall": "rimraf node_modules/tsutils/node_modules/typescript"

(Note: rimraf must be installed as devDependency)

Explain: to force tsutils (which is used by tslint) to use the project TypeScript version, instead of its own devDependency TypeScript version.

Is anyone still seeing this problem?

I'm also having a similar problem. I have managed to solve the problem by running
rm -rf node_modules/tsutils/node_modules/typescript
but I think this is not the best solution (In my opinion).

That seems to be a bug with Yarn, as mentioned in https://github.com/angular/angular-cli/issues/10990#issuecomment-440611661. I'm not sure there's anything we can do about that...

But for what it's worth, I just tried with yarn v1.12.3 on a new project and didn't see anything inside node_modules/tsutils/node_modules. Maybe it was somehow fixed on their side.

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._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hartjo picture hartjo  路  3Comments

IngvarKofoed picture IngvarKofoed  路  3Comments

MateenKadwaikar picture MateenKadwaikar  路  3Comments

NCC1701M picture NCC1701M  路  3Comments

JanStureNielsen picture JanStureNielsen  路  3Comments