Angular-cli aot build在生产模式下失败

问题描述 投票:3回答:1

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

./src/main.ts中的错误找不到模块:错误:无法解析'C:... \\ src'中的'./$$_gendir/app/app.module.ngfactory'@ ./src/main .ts 2:0-74 @ multi ./src/main.ts

错误的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 ERR! npm v3.10.10 npm ERR! 代码ELIFECYCLE npm ERR! [email protected] ng: ng "build" "--prod" npm ERR! 退出状态1 npm ERR! 错误的ERR! 在[email protected] ng脚本'ng“build”“--prod”'失败。 错误的ERR! 确保安装了最新版本的node.js和npm。 错误的ERR! 如果你这样做,这很可能是fol-mcdean包的问题,​​npm ERR! 不是与npm本身。 错误的ERR! 告诉作者你的系统失败了:npm ERR! ng“build”“ - prod”npm ERR! 您可以使用以下命令获取有关如何为此项目打开问题的信息:npm ERR!
npm错误关于错误! 或者,如果没有,您可以通过以下方式获取他们的信息:npm ERR! npm owner ls fol-mcdean npm ERR! 上面可能有额外的日志记录输出。

错误的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进行了一些调试

事实证明它在这些方面打破了:

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';

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

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

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

它奏效了!

所以,剩下的就是:

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

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

2)用生产值替换模块中的process.env.NODE_ENV(某些库需要这样做,比如反应)。

3)在代码上运行UglifyJS

所以我没有任何服务工作者,process.env.NODE_ENV也不适用......这是UglifyJS吗? 不知道下一步该怎么做。 有什么建议?

node.js angular angular-cli angular2-aot
1个回答
1
投票

我对此问题的解决方案和调查如下: https//github.com/angular/angular-cli/issues/6426

一般来说,原因似乎是在cssnano和一个空URL(“”)。

© www.soinside.com 2019 - 2024. All rights reserved.