1. 程式人生 > >Angular CLI 升級 6.0 之後遇到的問題

Angular CLI 升級 6.0 之後遇到的問題

ces eval term back parse ray direct lock webpack

Angular CLI 1.7.4 在使用 ng build --prod 會構建失敗,而 ng build 是正常的。比較好的解決辦法是使用 ng build --prod --extract-license=false 或者 ng build --prod --no-extract-license

最近將 Angular CLI 升級到 6.X 之後,直接 ng build 會報以下錯誤,ng serve 也是如此。

95% emitting LicenseWebpackPlugin(node:6252) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open 'D:\X\project\Angular-examples\angular-test\node_modules\_@[email protected]@@angular\package.json'
    at Object.fs.openSync (fs.js:646:18)
    at Object.fs.readFileSync (fs.js:551:33)
    at LicenseExtractor.readPackageJson (D:\X\project\Angular-examples\angular-test\node_modules\[email protected]@license-webpack-plugin\dist\LicenseExtractor.js:126:23)
    at LicenseExtractor.parsePackage (D:\X\project\Angular-examples\angular-test\node_modules\[email protected]@license-webpack-plugin\dist\LicenseExtractor.js:23:32)
    at ModuleProcessor.processPackage (D:\X\project\Angular-examples\angular-test\node_modules\[email protected]@license-webpack-plugin\dist\ModuleProcessor.js:39:46)
    at ModuleProcessor.processFile (D:\X\project\Angular-examples\angular-test\node_modules\[email protected]@license-webpack-plugin\dist\ModuleProcessor.js:36:21)
    at fileCallback (D:\X\project\Angular-examples\angular-test\node_modules\[email protected]@license-webpack-plugin\dist\LicenseWebpackPlugin.js:101:61)
    at moduleCallback (D:\X\project\Angular-examples\angular-test\node_modules\[email protected]@license-webpack-plugin\dist\LicenseWebpackPlugin.js:108:21)
    at D:\X\project\Angular-examples\angular-test\node_modules\[email protected]@license-webpack-plugin\dist\LicenseWebpackPlugin.js:120:29
    at Array.forEach (<anonymous>)
    at emitCallback (D:\X\project\Angular-examples\angular-test\node_modules\[email protected]@license-webpack-plugin\dist\LicenseWebpackPlugin.js:86:32)
    at _err0 (eval at create (D:\X\project\Angular-examples\angular-test\node_modules\[email protected]@tapable\lib\HookCodeFactory.js:24:12), <anonymous>:19:1)
    at callback (D:\X\project\Angular-examples\angular-test\node_modules\[email protected]@copy-webpack-plugin\dist\index.js:77:17)
    at D:\X\project\Angular-examples\angular-test\node_modules\[email protected]@copy-webpack-plugin\dist\index.js:118:24
    at <anonymous>
(node:6252) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:6252) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

但是使用 ng build --prod 是正常的。同樣地,使用 ng build --extract-license=false 也可以解決問題。

簡單看一下,問題是由 license-webpack-plugin 插件引起的。這款插件用於輸出第三方插件的許可協議。老外比較重視版權吧。但是不知道為什麽總是在這個地方出問題。

Angular CLI 升級 6.0 之後遇到的問題