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

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

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

95% emitting LicenseWebpackPlugin(node:6252) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open 'D:\X\project\Angular-examples\angular-test\node_modules\_@angular_common@6.0.2@@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\_license-webpack-plugin@1.3.1@license-webpack-plugin\dist\LicenseExtractor.js:126:23)
    at LicenseExtractor.parsePackage (D:\X\project\Angular-examples\angular-test\node_modules\_license-webpack-plugin@1.3.1@license-webpack-plugin\dist\LicenseExtractor.js:23:32)
    at ModuleProcessor.processPackage (D:\X\project\Angular-examples\angular-test\node_modules\_license-webpack-plugin@1.3.1@license-webpack-plugin\dist\ModuleProcessor.js:39:46)
    at ModuleProcessor.processFile (D:\X\project\Angular-examples\angular-test\node_modules\_license-webpack-plugin@1.3.1@license-webpack-plugin\dist\ModuleProcessor.js:36:21)
    at fileCallback (D:\X\project\Angular-examples\angular-test\node_modules\_license-webpack-plugin@1.3.1@license-webpack-plugin\dist\LicenseWebpackPlugin.js:101:61)
    at moduleCallback (D:\X\project\Angular-examples\angular-test\node_modules\_license-webpack-plugin@1.3.1@license-webpack-plugin\dist\LicenseWebpackPlugin.js:108:21)
    at D:\X\project\Angular-examples\angular-test\node_modules\_license-webpack-plugin@1.3.1@license-webpack-plugin\dist\LicenseWebpackPlugin.js:120:29
    at Array.forEach (<anonymous>)
    at emitCallback (D:\X\project\Angular-examples\angular-test\node_modules\_license-webpack-plugin@1.3.1@license-webpack-plugin\dist\LicenseWebpackPlugin.js:86:32)
    at _err0 (eval at create (D:\X\project\Angular-examples\angular-test\node_modules\_tapable@1.0.0@tapable\lib\HookCodeFactory.js:24:12), <anonymous>:19:1)
    at callback (D:\X\project\Angular-examples\angular-test\node_modules\_copy-webpack-plugin@4.5.1@copy-webpack-plugin\dist\index.js:77:17)
    at D:\X\project\Angular-examples\angular-test\node_modules\_copy-webpack-plugin@4.5.1@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-licenses=false 也能夠解決問題。web

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

--- 2018.7.13 ---json

新增解決方法:今天忽然發現使用 yarn 安裝依賴則沒有問題。使用 npm 安裝依賴以後,因爲某些 angular 插件的文件夾沒有 package.json(在下一層文件夾),因此 license-webpack-plugin 在抽取許可協議時會出錯,可是使用 yarn 安裝依賴時則不會出現這類文件夾,因此運行正常。promise

相關文章
相關標籤/搜索