angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Module build failed: TypeError: Cannot read property 'newLine' of undefined

Open hozefam opened this issue 9 years ago • 77 comments

ERROR in multi main Module not found: Error: Can't resolve 'webpack-dev-server/client?http://localho st:4200/' in 'D:\Hozefa\Ang\FirstApp\TestApp' @ multi main

Anyone?

OS?

Windows 7

Versions.

angular-cli: 1.0.0-beta.24 node: 4.4.6 os: win32 x64 @angular/common: 2.4.1 @angular/compiler: 2.4.1 @angular/core: 2.4.1 @angular/forms: 2.4.1 @angular/http: 2.4.1 @angular/platform-browser: 2.4.1 @angular/platform-browser-dynamic: 2.4.1 @angular/router: 3.4.1 @angular/compiler-cli: 2.4.1

The log given by the failure.

ERROR in multi main Module not found: Error: Can't resolve 'webpack-dev-server/client?http://localho st:4200/' in 'D:\Hozefa\Ang\FirstApp\TestApp' @ multi main

ERROR in ./src/main.ts Module build failed: TypeError: Cannot read property 'newLine' of undefined at Object.getNewLineCharacter (D:\Hozefa\Ang\FirstApp\TestApp\node_modules\t ypescript\lib\typescript.js:8062:20) at Object.createCompilerHost (D:\Hozefa\Ang\FirstApp\TestApp\node_modules\ty pescript\lib\typescript.js:44978:26) at Object.ngcLoader (D:\Hozefa\Ang\FirstApp\TestApp\node_modules@ngtools\we bpack\src\loader.js:171:31) @ multi main

hozefam avatar Dec 29 '16 12:12 hozefam

shorthand of @hnrchrdl's solution, all in one:

rm -rf node_modules && npm cache clean && npm uninstall --save angular-cli; npm uninstall -g angular-cli; npm i --save @angular/cli && npm i -g @angular/cli && npm i

mmathys avatar Feb 15 '17 14:02 mmathys

@mmathys your command got truncated in github. This is what I received in email notification:

rm -rf node_modules && npm cache clean && npm uninstall --save angular-cli && npm uninstall -g angular-cli && npm i --save @angular/cli && npm i -g @angular/cli && npm i && npm start

hnrchrdl avatar Feb 15 '17 16:02 hnrchrdl

@mmathys I needed 'sudo' for the -g installs/uninstallls, otherwise, just what I needed :)

tomjon avatar Feb 16 '17 10:02 tomjon

In my case, this error was because I updated to beta.32 and I didn't noticed that the node_modules folder was not completely removed. After removing the folder manually, I got it working.

manuelreina avatar Feb 18 '17 19:02 manuelreina

it need delete node_module ,uninstall -g angular-cli and and angular/cli and install @angular/cli

yuerdev avatar Feb 24 '17 03:02 yuerdev

why do we need the cli locally and globally?

quantuminformation avatar Feb 24 '17 18:02 quantuminformation

Because for example when you're building the project, you want to use ng build (not ./node_modules/@angular/cli/bin/ng build).

mmathys avatar Feb 25 '17 09:02 mmathys

I am getting the same error, but on circle/ci. Everything works fine locally on my mac. Naturally, since circle/ci builds everything from scratch, the advice to rm node_modules does really apply :( I checked the dependencies, and everything is exact other than ngrx additions. I even created a new angular-cli project and just copied everything over just in case :(

ERROR in ./src/main.ts
Module build failed: TypeError: Cannot read property 'newLine' of undefined
    at Object.getNewLineCharacter (/home/ubuntu/angular2-ngrx-example/node_modules/typescript/lib/typescript.js:9426:20)
    at Object.createCompilerHost (/home/ubuntu/angular2-ngrx-example/node_modules/typescript/lib/typescript.js:62475:26)
    at Object.ngcLoader (/home/ubuntu/angular2-ngrx-example/node_modules/@ngtools/webpack/src/loader.js:329:31)
 @ multi ./src/main.ts

ERROR in ./src/polyfills.ts
Module build failed: TypeError: Cannot read property 'newLine' of undefined
    at Object.getNewLineCharacter (/home/ubuntu/angular2-ngrx-example/node_modules/typescript/lib/typescript.js:9426:20)
    at Object.createCompilerHost (/home/ubuntu/angular2-ngrx-example/node_modules/typescript/lib/typescript.js:62475:26)
    at Object.ngcLoader (/home/ubuntu/angular2-ngrx-example/node_modules/@ngtools/webpack/src/loader.js:329:31)
 @ multi ./src/polyfills.ts

ERROR in ./src/test.ts
Module build failed: TypeError: Cannot read property 'newLine' of undefined
    at Object.getNewLineCharacter (/home/ubuntu/angular2-ngrx-example/node_modules/typescript/lib/typescript.js:9426:20)
    at Object.createCompilerHost (/home/ubuntu/angular2-ngrx-example/node_modules/typescript/lib/typescript.js:62475:26)
    at Object.ngcLoader (/home/ubuntu/angular2-ngrx-example/node_modules/@ngtools/webpack/src/loader.js:329:31)
28 02 2017 12:47:04.259:ERROR [karma]: { Error: no such file or directory
    at MemoryFileSystem.readFileSync (/home/ubuntu/angular2-ngrx-example/node_modules/webpack-dev-middleware/node_modules/memory-fs/lib/MemoryFileSystem.js:107:10)
    at MemoryFileSystem.(anonymous function) [as readFile] (/home/ubuntu/angular2-ngrx-example/node_modules/webpack-dev-middleware/node_modules/memory-fs/lib/MemoryFileSystem.js:300:34)
    at doRead (/home/ubuntu/angular2-ngrx-example/node_modules/@angular/cli/node_modules/karma-webpack/lib/karma-webpack.js:205:29)
    at Plugin.readFile (/home/ubuntu/angular2-ngrx-example/node_modules/@angular/cli/node_modules/karma-webpack/lib/karma-webpack.js:210:7)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
  code: 'ENOENT',
  errno: 34,
  message: 'no such file or directory',
  path: '/_karma_webpack_/src/polyfills.ts' }
28 02 2017 12:47:04.269:ERROR [karma]: { Error: no such file or directory
    at MemoryFileSystem.readFileSync (/home/ubuntu/angular2-ngrx-example/node_modules/webpack-dev-middleware/node_modules/memory-fs/lib/MemoryFileSystem.js:107:10)
    at MemoryFileSystem.(anonymous function) [as readFile] (/home/ubuntu/angular2-ngrx-example/node_modules/webpack-dev-middleware/node_modules/memory-fs/lib/MemoryFileSystem.js:300:34)
    at doRead (/home/ubuntu/angular2-ngrx-example/node_modules/@angular/cli/node_modules/karma-webpack/lib/karma-webpack.js:205:29)
    at Plugin.readFile (/home/ubuntu/angular2-ngrx-example/node_modules/@angular/cli/node_modules/karma-webpack/lib/karma-webpack.js:210:7)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
  code: 'ENOENT',
  errno: 34,
  message: 'no such file or directory',
  path: '/_karma_webpack_/src/test.ts' }
npm ERR! Test failed.  See above for more details.

egervari avatar Feb 28 '17 12:02 egervari

you might want to check angular-cli.json and package.json for outdated local angular-cli versions.

phil294 avatar Mar 03 '17 02:03 phil294

I'm seeing exactly the same error as @egervari reported. I'm writing my code on a Windows 8.1, build, test, e2e and lint works perfectly. Once I push my code to CI (using a Linux build agent) it fails with the following errors: npm run build

ERROR in AppModule is not an NgModule

ERROR in ./src/main.ts
Module build failed: TypeError: Cannot read property 'newLine' of undefined
    at Object.getNewLineCharacter (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/typescript/lib/typescript.js:9514:20)
    at Object.createCompilerHost (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/typescript/lib/typescript.js:63770:26)
    at Object.ngcLoader (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/@ngtools/webpack/src/loader.js:329:31)
 @ multi ./src/main.ts

ERROR in ./src/polyfills.ts
Module build failed: TypeError: Cannot read property 'newLine' of undefined
    at Object.getNewLineCharacter (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/typescript/lib/typescript.js:9514:20)
    at Object.createCompilerHost (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/typescript/lib/typescript.js:63770:26)
    at Object.ngcLoader (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/@ngtools/webpack/src/loader.js:329:31)

npm run test

ERROR in ./src/main.ts
Module build failed: TypeError: Cannot read property 'newLine' of undefined
    at Object.getNewLineCharacter (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/typescript/lib/typescript.js:9514:20)
    at Object.createCompilerHost (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/typescript/lib/typescript.js:63770:26)
    at Object.ngcLoader (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/@ngtools/webpack/src/loader.js:329:31)
 @ multi ./src/main.ts

ERROR in ./src/polyfills.ts
Module build failed: TypeError: Cannot read property 'newLine' of undefined
    at Object.getNewLineCharacter (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/typescript/lib/typescript.js:9514:20)
    at Object.createCompilerHost (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/typescript/lib/typescript.js:63770:26)
    at Object.ngcLoader (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/@ngtools/webpack/src/loader.js:329:31)
 @ multi ./src/polyfills.ts

ERROR in ./src/test.ts
Module build failed: TypeError: Cannot read property 'newLine' of undefined
    at Object.getNewLineCharacter (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/typescript/lib/typescript.js:9514:20)
    at Object.createCompilerHost (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/typescript/lib/typescript.js:63770:26)
    at Object.ngcLoader (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/@ngtools/webpack/src/loader.js:329:31)
08 03 2017 11:25:15.129:ERROR [karma]: { Error: no such file or directory
    at MemoryFileSystem.readFileSync (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/webpack-dev-middleware/node_modules/memory-fs/lib/MemoryFileSystem.js:107:10)
    at MemoryFileSystem.(anonymous function) [as readFile] (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/webpack-dev-middleware/node_modules/memory-fs/lib/MemoryFileSystem.js:300:34)
    at doRead (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/@angular/cli/node_modules/karma-webpack/lib/karma-webpack.js:205:29)
    at Plugin.readFile (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/@angular/cli/node_modules/karma-webpack/lib/karma-webpack.js:210:7)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
  code: 'ENOENT',
  errno: 34,
  message: 'no such file or directory',
  path: '/_karma_webpack_/src/polyfills.ts' }
08 03 2017 11:25:15.138:ERROR [karma]: { Error: no such file or directory
    at MemoryFileSystem.readFileSync (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/webpack-dev-middleware/node_modules/memory-fs/lib/MemoryFileSystem.js:107:10)
    at MemoryFileSystem.(anonymous function) [as readFile] (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/webpack-dev-middleware/node_modules/memory-fs/lib/MemoryFileSystem.js:300:34)
    at doRead (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/@angular/cli/node_modules/karma-webpack/lib/karma-webpack.js:205:29)
    at Plugin.readFile (/var/lib/jenkins/workspace/Intelliflo/Microservice.DeveloperHub/IP-14137/node_modules/@angular/cli/node_modules/karma-webpack/lib/karma-webpack.js:210:7)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
  code: 'ENOENT',
  errno: 34,
  message: 'no such file or directory',
  path: '/_karma_webpack_/src/test.ts' }

OS?

Windows 8.1

Versions.

angular-cli: 1.0.0-rc.1 node: 6.10.0 os: win32 x64 @angular/common: 2.4.9 @angular/compiler: 2.4.9 @angular/core: 2.4.9 @angular/forms: 2.4.9 @angular/http: 2.4.9 @angular/platform-browser: 2.4.9 @angular/platform-browser-dynamic: 2.4.9 @angular/router: 3.4.9 @angular/compiler-cli: 2.4.9 typescript: 2.2.1

jlouros avatar Mar 08 '17 11:03 jlouros

This specific error (TypeError: Cannot read property 'newLine' of undefined) seems to appear due to different versions of either TypeScript. If you're experiencing different behaviour on different machines, make sure you're using the same TS version everywhere.

You can test this by running npm ls typescript on your project. It's likely you have a bad mix of TS versions.

Angular version 2 works only with Typescript 2.0, while Angular version 4 works with 2.1 and up.

filipesilva avatar Mar 08 '17 11:03 filipesilva

@filipesilva thanks for your response. I was actually able to figure out the problem. As you stated on previous comments, this error is reported when an older version of Angular-CLI is installed. For me it was always picking [email protected] instead of rc.1. I was able to figure that out when I ran npm ls on build agent workspace. This was happening even when I followed the uninstall guide.

To fix this problem for me I had to:

  • after npm install run npm ls just to double check the installed angular-cli
  • ask a member from DevOps (or somebody with 'sudo' access on the build agent) to wipe-out the entire workspace and run npm cache clear

Hopefully this can you @egervari

jlouros avatar Mar 08 '17 11:03 jlouros

Hi I'm having the same issue. My SO is W10, and I created the project two weeks ago. I was working fine until today, I copied my code to make a new repo and cleand the "node_modules" folder, run npm install and doesn't work since then. My main problem is that I also clean the original folder so I had to run npm install on both projects I've tried every solution I could find and of course the angular-cli update guide. Nothing works. I get this message and can't run any of my two projects. This is my ng version:

@angular/cli: 1.0.0-rc.2
node: 6.10.0
os: win32 x64
@angular/common: 2.4.9
@angular/compiler: 2.4.9
@angular/core: 2.4.9
@angular/flex-layout: 2.0.0-rc.1
@angular/forms: 2.4.9
@angular/http: 2.4.9
@angular/material: 2.0.0-beta.2
@angular/platform-browser: 2.4.9
@angular/platform-browser-dynamic: 2.4.9
@angular/router: 3.4.9
@angular/cli: 1.0.0-rc.2
@angular/compiler-cli: 2.4.9
@ngtools/webpack: 1.2.13

MartinFreire avatar Mar 15 '17 22:03 MartinFreire

@egervari I'm not sure why but I rebuilt the built without cache and it passed on circleci. Hope it helps.

gamalielhere avatar Mar 15 '17 23:03 gamalielhere

Ok, so I could make it work. I tried multiple times the steps in the update guide and didn't work form me.

This is the last set of steps I do and it works in my case:

  1. Unistall NodeJS (yes I did that)
  2. Delete all the folders in C:\Users{user}\AppData\Local\Temp that stars with npm
  3. Delete the folder C:\Users{user}\AppData\Roaming\npm
  4. Delete the folder C:\Users{user}\AppData\Roaming\npm-cache
  5. Delete the folder node_module in both projects
  6. Restart my PC (because I detected that W10 has some folders lock and that didn't let me run nmp cache clean
  7. Install NodsJs
  8. Run npm install --save-dev @angular/cli@latest
  9. Run npm install
  10. Run npm install --save-dev @angular/cli@latest AGAIN

I only repeated the npm install --save-dev @angular/cli@latest after the npm install once, so I don't know if had anything to do with the problem. After the second time I run this command I see that the library has changed (it was on yellow) `-- @angular/[email protected] (I guess this is wath I was doing wrong)

Hope it works for someone else!

MartinFreire avatar Mar 16 '17 03:03 MartinFreire

I had the same issue, after reading this entire thread and trying everything the problem still existed. Turns out that the cli was using a different version of webpack than what my project is using. Once I got those version in sync then the error went away. I have a new Angular 4 project Universal demo so the webpack outside the cli was for server side code i guess.

jbeckton avatar Mar 24 '17 22:03 jbeckton

@egervari Have you had any luck with this? I think I'm in the same boat. Locally, my angular 2.4.5, cli 1.0.0-rc1 app runs fine with either Typescript 2.0.0 and 2.2.1, but neither work on TravisCI.

dancancro avatar Mar 27 '17 21:03 dancancro

FYI. Had this issue too, cli migration guides etc did not help . Solved the problem removing "@ngtools/webpack" and "webpack" from my package.json dependencies and reinstalling all modules. Hope it can save couple of hours of your time :)

thisisbb avatar Mar 29 '17 06:03 thisisbb

Ran into this issue today. In our case it resulted from a mismatch of peer dependencies because we had almost all @angular packages at 4.0.0, @angular/cli at 1.0.0, but @angular/compiler-cli at ^4.0.0 which resulted in 4.0.2 being installed for that package. ng build failed with "Cannot read property 'newLine' of undefined" error.

doubletriplezero avatar Apr 13 '17 16:04 doubletriplezero

Have similar issue with tests on Travis-CI...with @angular/cli 1.0.0 & @angular 4.0.0

locally the tests ran fine.

Travis-CI Uncaught TypeError: Cannot read property 'apply' of undefined

image

playground avatar Apr 14 '17 03:04 playground