在生产模式下,Anglu-cli aot构build失败

在编译失败的错误:模块构build失败:TypeError:不能在Object.createCompilerHost()读取属性Object.getNewLineCharacter(C:… \ node_modules \ typescript \ lib \ typescript.js:9581:20)undefined属性'newLine' (C:… \ node_modules \ @ngtools \ webpack \ src \ loader.js:386:33):TypeError(C:… \ node_modules \ typescript \ lib \ typescript.js:66675:26):Object.ngcLoader :不能读取未定义的属性'newLine'

./src/main.ts中的错误未find模块:错误:无法parsing“C:… \ src”中的“./$$_gendir/app/app.module.ngfactory”@ ./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! 节点v6.10.3 npm错误! npm v3.10.10 npm ERR! 代码ELIFECYCLE npm ERR! fol-mcdean@0.1.0 ng: ng "build" "--prod" npm ERR! 退出状态1 npm ERR! npm ERR! 在fol-mcdean@0.1.0 ng脚本“ng”build“”–prod“”失败。 npm ERR! 确保你已经安装了最新版本的node.js和npm。 npm ERR! 如果这样做,这很可能是一个fol-mcdean软件包的问题,​​npm ERR! 而不是npm本身。 npm ERR! 告诉作者,这在你的系统上失败:npm ERR! ng“build”“–prod”npm ERR! 您可以通过以下方式获取有关如何为此项目打开问题的信息:npm ERR!
npm错误fol-mcdean npm ERR! 或者,如果这不可用,您可以通过以下方式获取他们的信息:npm ERR! npm所有者ls fol-mcdean npm ERR! 上面可能还有其他的日志输出。

npm ERR! 请包括以下文件与任何支持请求:npm ERR! C:\ NPM-的debug.log

我有一个项目,使用@angular 4.1.3和@ angular / cli 1.1.0-rc.0(尝试1.04以及相同的结果)。 所以这个项目使用ng build –aot = true来生成,但是使用ng build –prod会失败。

我对\ node_modules @ ngtools \ webpack \ src \ loader.js进行了一些debugging

事实certificate,它在这些方面打破了:

 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 ... } } 

而失败的文件是index.ts:

 export * from './GJLog.component'; 

我也检查了所有软件包的所有版本,清理caching,重新安装节点..一切..但在AOT模式仍然是同样的问题。 在同一时间,它完美编译aot = false …

然后我决定阅读–prod和not –prod之间的区别:运行以下命令:

 npm run ng build -- --aot=true --environment=prod --output-hashing=all --sourcemaps=false --extract-css=true 

它的工作!

所以,剩下的是这样的:

–prod还设置了以下不可标记的设置:

1)如果在.angular-cli.json中configuration,则添加服务工作者。

2)使用生产值replace模块中的process.env.NODE_ENV(这对某些库是必需的,如反应)。

3)在代码上运行UglifyJS

所以我没有任何服务人员,而process.env.NODE_ENV也不适用…那么这个UglifyJS呢? 不知道下一步该怎么做。 有什么build议么?

我的解决scheme和调查问题在这里: https : //github.com/angular/angular-cli/issues/6426

一般来说,原因是在cssnano和一个空的url(“”)。