Module build failed: TypeError: Cannot read property 'newLine' of undefined
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
We avoid using global commands (we only use local ng) for this and other reasons, as we believe build determinism is important, as is consistency between development and production build environments. I did encounter the error TypeError: Cannot read property 'newLine' of undefined today in one of my recently revived development environments, apparently due to old dependencies, as suggested above. Removing node_modules in the project and rerunning npm install, as recommended above, resolved the problem. The current dependencies of the project include:
"@angular/cli": "1.0.0",
"@angular/common": "4.0.0",
"@angular/compiler": "4.0.0",
"@angular/compiler-cli": "4.0.0",
"@angular/core": "4.0.0",
"@angular/forms": "4.0.0",
"@angular/http": "4.0.0",
"@angular/platform-browser": "4.0.0",
"@angular/platform-browser-dynamic": "4.0.0",
"@angular/platform-server": "4.0.0",
"@angular/router": "4.0.0",
"core-js": "^2.4.1",
"rxjs": "~5.0.3",
"typescript": "^2.1.4",
"zone.js": "^0.8.4"
But it had been updated and rebuilt from older versions of angular (2.x) and angular-cli (1.x beta).
I had the same Module build failed: TypeError: Cannot read property 'newLine' of undefined on a cloned copy of the app.
I have been working on a local version that had Angular 4.0.2, and when another developer pulled the latest version, they started getting that error. I made another cloned copy and was getting that error. I tried a bunch of the suggestions above.
Turned out all of the angular dependancies were on 4.1.0 but the @angular/cli was on 1.0.0. In my package.json, I had angular dependacies as ^4.0.0, and @angular/cli at 1.0.0. I changed "@angular/cli": "^1.0.1", ran npm install` and the app is back to compiling as expected.
I have a project with exact same error, using @angular 4.1.3 and @angular/cli 1.1.0-rc.0 (tried 1.04 as well with the same result). So the project builds fine with
ng build --prod --aot=false
but fails with this error using ng build --prod.
I did some debugging of \node_modules@ngtools\webpack\src\loader.js
And it turns out it breaks on these lines:
function ngcLoader() {
...
const sourceFileName = this.resourcePath; //here is index.ts file, I'll show it later
const plugin = this._compilation._ngToolsWebpackPluginInstance; //plugin === undefined here!
if (plugin && plugin instanceof plugin_1.AotPlugin) { //and of course this is false
...
} else {
const options = loaderUtils.getOptions(this) || {}; //and options are {} here...
...
const compilerHost = ts.createCompilerHost(compilerOptions); //and of cource it breaks here
...
}
}
And the file on which it fails is index.ts:
export * from './GJLog.component';
I've also checked all the versions of all packages, cleaned cache, reinstalled node.. Everything.. But still the same problem in AOT mode. In the same time, it perfectly compiles with aot=false...
Any hints on what to debug next, which direction to investigate?
Thank you!
Even more, the project builds just fine like this:
npm run ng build -- --aot=true --environment=prod --output-hashing=all --sourcemaps=false --extract-css=true
But does not build like this:
npm run build -- --prod --aot=true
Let's read the docs:
--prod also sets the following non-flaggable settings:
- Adds service worker if configured in .angular-cli.json.
- Replaces process.env.NODE_ENV in modules with the production value (this is needed for some libraries, like react). +Runs UglifyJS on the code
I don't have any service workers, I don't use any process.env.NODE_ENV.
So this must be related to UglifyJS?
Can I somehow disable running uglify js just to make sure it's the reason?
We have the same issue. With every new loader in webpack you get a new bug. Nothing is really tested :-(
I've just opened a separate issue for this... So probably it'll attract more attention...
Cannot read property 'newLine' of undefined at Object.getNewLineCharacter while doing ng serve , previously it was working from today it is giving problem
Please also leave a note about your issue here: https://github.com/angular/angular-cli/issues/6426
There are some undocumented or badly documented things that --aot --prod does with your code. For example, cssnano is also run,
Please take a look https://github.com/angular/angular-cli/issues/6426 here for my solution.
Probably you made the same mistake as I did...
Oh this is a painful bug.Uninstall reinstall more than 100 times but still not resolved An Module build failed: TypeError: Cannot read property 'newLine' of undefined.
"@angular/common": "2.4.7", "@angular/compiler": "2.4.7", "@angular/compiler-cli": "^2.4.0", "@angular/core": "2.4.7", "@angular/forms": "2.4.7", "@angular/http": "2.4.7", "@angular/platform-browser": "2.4.7", "@angular/platform-browser-dynamic": "2.4.7", "@angular/cli": "^1.0.0",
Some one please help! :(
That's probably a bug in syntax like the one I had... In my case it had nothing to do with dependencies... Does it build in debug mode?
Same here, it worked. I am still using 1.0.0 version, week ago everything fine, currently I got the newLine error.
someone solve this error?
I have still trying to solve the next errors when I run ng serve
ERROR in multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts
Module not found: Error: Can't resolve 'webpack-dev-server/client?http://localhost:4200' in '/Users/codebo1/Projects/monitor-client/client'
@ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts
ERROR in ./src/main.ts
Module build failed: Error: Cannot find module 'webpack/lib/dependencies/ContextElementDependency'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/codebo1/Projects/monitor-client/client/node_modules/@ngtools/webpack/src/plugin.js:9:34)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/codebo1/Projects/monitor-client/client/node_modules/@ngtools/webpack/src/index.js:30:10)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
@ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts
ERROR in ./src/polyfills.ts
Module build failed: Error: Cannot find module 'webpack/lib/dependencies/ContextElementDependency'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/codebo1/Projects/monitor-client/client/node_modules/@ngtools/webpack/src/plugin.js:9:34)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/codebo1/Projects/monitor-client/client/node_modules/@ngtools/webpack/src/index.js:30:10)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
@ multi ./src/polyfills.ts
webpack: Failed to compile.
Same here. Recovered from backup that was really working fine: error. All combinations of cache clean, uninstall, update: error!
I've spent 16 hours working on this problem with a angular-cli project. I've tried every solution listed here, with nothing that gets it working. I wish I could provide a repro, but doesn't seem to happen with any other CLI project on my machine.
I feel pretty frustrated because I thought the Angular team had ironed out most of the issues with the CLI. But after this ordeal, I'm still not convinced it's a stable platform yet. The project in question had been left alone for 3 months, then cloning it onto my Windows 8 computer and reinstalling the npm dependencies causes the "newline" error message when I try to ng serve it. I tried everything on my MacBook Pro, too, and got the same error.
I think I'm just a crappy developer, but the complexity of this build process and tooling is just overwhelming. It seems any productivity gains that Angular provided me were wiped away by the time I've spent troubleshooting a black hole of build issues, like this one.
Did you check my solution?
Yeah, I greped my entire project for url("") and nothing came back, if that's what you mean.
I'm guessing it could be some other CSS-related syntax issue then? Unfortunately, I have over 100 components. Trying to debug which CSS file is causing the problem is going to take a while.
I've spent a lot of time on this problem. But it solved just by update angular-cli from v1.1.0 to v1.1.1
Guys you have to completely delete npm packages, in Windows it is in your user profile. This problem caused the npm update on my machine. When I cleaned all the packages previously downloaded in global, it works like a charm.
On Jun 12, 2017 18:37, "Jon Gunter" [email protected] wrote:
I've spent 16 hours working on this problem with a angular-cli project. I've tried every solution listed here, with nothing that gets it working. I wish I could provide a repro, but doesn't seem to happen with any other CLI project on my machine.
I feel pretty frustrated because I thought the Angular team had ironed out most of the issues with the CLI. But after this, I'm still not convinced it's a stable platform yet. The project in question had been left alone for 3 months, then cloning it onto my computer and reinstalling the npm dependencies causes the "newline" error message when I try to ng serve it.
— 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-307844896, or mute the thread https://github.com/notifications/unsubscribe-auth/AFA0wSfzdWN2apG1G0dfoMr1bsZAZgF0ks5sDWkzgaJpZM4LXj2l .
Thanks for your responses. I tried the following on my Mac and PC with no solution:
- Uninstalling node/npm and reinstalling
- Removing all my global packages and reinstalling them
- Removing all my local npm packages and reinstalling
- Updating the CLI to v1.1.1
- Followed the entire CLI migration guide
- Deleted and re-cloned the project from source control
- Updated node to the latest version (8.1.0)
Furthermore, this project in question seems to be working on one of my colleague's Macs, which is strange because it doesn't work on my Mac, which is the exact same model with the exact same MacOS version. I npm shrinkwraped the dependencies there and tried to remove all local/global node modules and reinstall on other machines. Still doesn't work.
We spent months putting this project together for a demo. I think I might be at my wits end with Angular right now. The fact that there's no useful error message or stack trace here is particularly infuriating for me.