Angular-cli aot build not working in production mode

ERROR error in child compilation: Module build failed: TypeError: Unable to read property newLine from undefined in Object.getNewLineCharacter (C: ... \ node_modules \ typescript \ lib \ typescript.js: 9581: 20) in Object.createCompilerHost (C: ... \ node_modules \ typescript \ lib \ typescript.js: 66675: 26) in Object.ngcLoader (C: ... \ node_modules \ @ngtools \ webpack \ src \ loader.js: 386: 33): TypeError: not possible read property 'newLine' of undefined

Mistake in. /src/main.ts Module not found: Error: Unable to 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! ELIFECYCLE code npm ERR! fol-mcdean@0.1.0 ng: ng "build" "--prod"

npm ERR! Output status 1 npm ERR! npm ERR! Failed to execute fol-mcdean@0.1.0 ng script 'ng "build" "--prod"'. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you are doing this, there is most likely a problem with the fol-mcdean package, npm ERR! and not with the hour itself. npm ERR! Tell the author it fails 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 this is not possible, you can get their information via: npm ERR! npm owner ls fol-mcdean npm ERR! There is probably an additional exit from the log 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 and also with the same result). So the project builds with ng build --aot = true but with this error ng build --prod is used in error.

I did some debugging \ node_modules @ngtools \ webpack \ src \ loader.js

And it turns out that it breaks into the following 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 it crashes is index.ts:

export * from './GJLog.component';

      

I also checked all versions of all packages, cleared the cache, reinstalled node .. Everything .. But still the same problem in AOT mode. At the same time it compiles fine with aot = false ...

Then I 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, the following remains:

- prod also sets the following unmanaged options:

1) Adds a service worker if configured in .angular-cli.json.

2) Replaces process.env.NODE_ENV in modules with production value (this is needed for some libraries like react).

3) Runs UglifyJS on code

So, I don't have any working services, and process.env.NODE_ENV is not applicable either ... So is this UglifyJS? Not sure what to do next. Any suggestions?

+3


source to share


1 answer


See my solution and researching the issue here: https://github.com/angular/angular-cli/issues/6426



All in all it seems that the reason was cssnano and the empty url ("").

+1


source







All Articles