ERROR in Child compilation failed: Module build failed: TypeError: Cannot read property 'newLine' of undefined at Object.getNewLineCharacter (C:...\node_modules\typescript\lib\typescript.js:9581:20) at Object.createCompilerHost (C:...\node_modules\typescript\lib\typescript.js:66675:26) at Object.ngcLoader (C:...\node_modules\@ngtools\webpack\src\loader.js:386:33): TypeError: Cannot read property 'newLine' of undefined
ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'C:...\src' @ ./src/main.ts 2:0-74 @ multi ./src/main.ts
npm ERR! Windows_NT 10.0.15063 npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "ng" "build" "--" "--prod" npm ERR! node v6.10.3 npm ERR! npm v3.10.10 npm ERR! code ELIFECYCLE npm ERR! [email protected] ng:
ng "build" "--prod"
npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] ng script 'ng "build" "--prod"'. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the fol-mcdean package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! ng "build" "--prod" npm ERR! You can get information on how to open an issue for this project with: npm ERR!
npm bugs fol-mcdean npm ERR! Or if that isn't available, you can get their info via: npm ERR! npm owner ls fol-mcdean npm ERR! There is likely additional logging output above.npm ERR! Please include the following file with any support request: npm ERR! C:...\npm-debug.log
I have a project with this, 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 --aot=true 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...
Then I've decided to read what's the difference between --prod and not --prod: And ran the following command:
npm run ng build -- --aot=true --environment=prod --output-hashing=all --sourcemaps=false --extract-css=true
And it worked!
So, remaining is this:
--prod also sets the following non-flaggable settings:
1) Adds service worker if configured in .angular-cli.json.
2) Replaces process.env.NODE_ENV in modules with the production value (this is needed for some libraries, like react).
3) Runs UglifyJS on the code
So I don't have any service workers, and process.env.NODE_ENV is not applicable either... So is this UglifyJS? Not sure what to do next. Any suggestions?