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

I've just discovered that if I check in node_modules from the "happy" computer, it works on both my other machines. Unfortunately, if I re-run npm install on those secondary machines, everything breaks again, meaning packages can only be installed/updated on one single dev's machine. Also, this is not a long-term solution, because checking in node_modules is a pretty bad practice, especially moving between MacOS and Windows.

Maybe @filipesilva has an idea?

jongunter avatar Jun 13 '17 15:06 jongunter

This seems to be a dependency issue, as copying the same package.json file into one of my blank "sandbox" cli projects yields the same error.

Check out my repro...this is broken on my machine, and I hope other people can reproduce this: https://github.com/jongunter/broken-ng-cli

jongunter avatar Jun 13 '17 15:06 jongunter

I have the same issue:

ng -v

@angular/cli: 1.0.3 node: 8.0.0 os: linux x64 @angular/common: 4.2.3 @angular/compiler: 4.2.3 @angular/core: 4.2.3 @angular/forms: 4.2.3 @angular/http: 4.2.3 @angular/platform-browser: 4.2.3 @angular/platform-browser-dynamic: 4.2.3 @angular/router: 4.2.3 @angular/cli: 1.0.3 @angular/compiler-cli: 4.2.3 @ngtools/webpack: 1.4.1

tsc -v

Version 2.3.4

Errors: ERROR in ./src/main.ts Module build failed: TypeError: Cannot read property 'newLine' of undefined at Object.getNewLineCharacter (/var/www/education/client-apps/node_modules/typescript/lib/typescript.js:9514:20) at Object.createCompilerHost (/var/www/education/client-apps/node_modules/typescript/lib/typescript.js:63770:26) at Object.ngcLoader (/var/www/education/client-apps/node_modules/@ngtools/webpack/src/loader.js:397:33) @ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts

ERROR in ./src/polyfills.ts Module build failed: TypeError: Cannot read property 'newLine' of undefined at Object.getNewLineCharacter (/var/www/education/client-apps/node_modules/typescript/lib/typescript.js:9514:20) at Object.createCompilerHost (/var/www/education/client-apps/node_modules/typescript/lib/typescript.js:63770:26) at Object.ngcLoader (/var/www/education/client-apps/node_modules/@ngtools/webpack/src/loader.js:397:33) @ multi ./src/polyfills.ts

I try each manual of packages reinstalling/upgrading but nothing can helps me. Are there any solutions?

andreaslancom avatar Jun 20 '17 15:06 andreaslancom

@filipesilva , this issue should be reopened. I have a reproducible test case posted above (if it's not reproducing the error for you, please let me know). Even if this is deemed as case of "operator error", there should be a more helpful error message to let the user know what's going on.

jongunter avatar Jun 20 '17 16:06 jongunter

I had this bug today because i was i had angular/cli version 1.1.2 installed, i resolved it by installing @angular/[email protected]

Steps include: npm uninstall @angular/cli npm install @angular/[email protected]

Hope that helps.

shahmhussain avatar Jun 21 '17 08:06 shahmhussain

If anyone was wondering, I have resolved this issue by ng newing a new project, and merging the package.json with my old non-working project (and trying to keep the dependencies from the new project). Luckily, everything worked, even though it meant a forced upgrade to Angular 4.

Still, I think this shouldn't be necessary...the error should tell me roughly what I need to fix.

jongunter avatar Jun 21 '17 15:06 jongunter

Thanks a lot. As @jongunter said I create new app and merge package.js and it's working now.

andreaslancom avatar Jun 21 '17 15:06 andreaslancom

I had the same error. I had to go through @MartinFreire 's steps and (don't ask me why) delete package.-ock.json .

ghost avatar Jun 22 '17 10:06 ghost

I looked into this during the weekend and have to say that @toverux explanation in https://github.com/angular/angular-cli/issues/3781#issuecomment-272284110 is spot on.

For projects using @angular/cli (and not @ngtools/webpack directly), this error happens if you have multiple versions of @ngtools/webpack in your dependencies. You can check if you do by running npm ls @ngtools/webpack (or yarn list @ngtools/webpack). You should remove any extra copies from your dependencies and make sure that your lock files are updated accordingly.

filipesilva avatar Jun 27 '17 11:06 filipesilva

@filipesilva Thank you. npm prune saved this for me.

uberroot4 avatar Jun 29 '17 10:06 uberroot4

Still receiving this error, despite having only one version of @ngtools/webpack installed.

npm ls @ngtools/webpack +-- @angular/[email protected] |-- @ngtools/[email protected] -- @ngtools/[email protected]

jdrake3 avatar Jul 19 '17 20:07 jdrake3

OS : Windows with Angular 4

"@angular/cli": "1.2.1", "@angular/material": "2.0.0-beta.6",

I just removed the caret from above two dependencies and performed following steps, everything started working perfectly.

  1. Remove node_module
  2. Uninstall angular cli from local and global
  3. Install the same version of angular cli in both
  4. Do "npm install"
  5. "ng serve"

prabhatojha avatar Jul 20 '17 05:07 prabhatojha

ERROR in ./src/main.ts Module build failed: TypeError: Cannot read property 'newLine' of undefined at Object.getNewLineCharacter (/home/user/Documents/projects/ayo6/node_modules/typescript/lib/typescript.js:9618:20) at Object.createCompilerHost (/home/user/Documents/projects/ayo6/node_modules/typescript/lib/typescript.js:66867:26) at Object.ngcLoader (/home/user/Documents/projects/ayo6/node_modules/@ngtools/webpack/src/loader.js:202:31) @ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts

ERROR in ./src/polyfills.ts Module build failed: TypeError: Cannot read property 'newLine' of undefined at Object.getNewLineCharacter (/home/user/Documents/projects/ayo6/node_modules/typescript/lib/typescript.js:9618:20) at Object.createCompilerHost (/home/user/Documents/projects/ayo6/node_modules/typescript/lib/typescript.js:66867:26) at Object.ngcLoader (/home/user/Documents/projects/ayo6/node_modules/@ngtools/webpack/src/loader.js:202:31) @ multi ./src/polyfills.ts webpack: Failed to compile.

I'm getting this when I run "ng serve".. Is this just a typescript error or more?

ghost avatar Jul 20 '17 14:07 ghost

OK, as many others have mentioned this is due to version mismatches with webpack or angular-cli, but never seems to be fixed by deleting the node_modules folder or re-installing / uninstalling packages manually.

I FINALLY managed to get this working by deleting node_modules folder AND the package-lock.json file... Then running npm install seemed to fix this for me.

macandcheese avatar Jul 26 '17 18:07 macandcheese

If I remember correctly my fix to the issue went something like this..

rm -r npm_modules sudo -i npm clear cache sudo npm -g uninstall @angular/cli perhaps "npm uninstall @angular/cli" locally if need be.. then install with npm again, I realised my problem was that somehow.. I managed to have a local version that was different that the global version and the older one was being used..

check versions ng -v, etc..also I used npm3 not npm ;)

On Wed, Jul 26, 2017 at 6:00 PM, Adam Tirella [email protected] wrote:

OK, as many others have mentioned this is due to version mismatches, but never seems to be fixed by deleting the node_modules folder or re-installing / uninstalling packages.

I FINALLY managed to get this working by deleting node_modules folder AND the package-lock.json file... Then running npm install seemed to fix this for me.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/3781#issuecomment-318133980, or mute the thread https://github.com/notifications/unsubscribe-auth/AGDyiP0_rQVX4NhNTuK22b861u3DCFmmks5sR37AgaJpZM4LXj2l .

ghost avatar Jul 26 '17 18:07 ghost

Hey, guys, my problem was solved due @macandcheese comment -

I FINALLY managed to get this working by deleting node_modules folder AND the package-lock.json file... Then running npm install seemed to fix this for me.

the @filipesilva rightly explained the reason of issue -

For projects using @angular/cli (and not @ngtools/webpack directly), this error happens if you have multiple versions of @ngtools/webpack in your dependencies. You can check if you do by running npm ls @ngtools/webpack (or yarn list @ngtools/webpack). You should remove any extra copies from your dependencies and make sure that your lock files are updated accordingly.

skiminock avatar Apr 30 '18 15:04 skiminock

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.