ng serve 报错: 95% emitting LicenseWebpackPlugin(node:21768) UnhandledPromiseRejectionWarning…

今天升级了Angular-cli版本到:Angular CLI: 6.2.4 后,初始化了个新项目,cnpm install 安装好依赖后 ng serve 报错。

报错信息如下:

** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
 95% emitting LicenseWebpackPlugin(node:21768) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open 'D:\me\angular\ngApp\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:\me\angular\ngApp\node_modules\[email protected]@license-webpack-plugin\dist\LicenseExtractor.js:126:23)
    at LicenseExtractor.parsePackage (D:\me\angular\ngApp\node_modules\[email protected]@license-webpack-plugin\dist\LicenseExtractor.js:23:32)
    at ModuleProcessor.processPackage (D:\me\angular\ngApp\node_modules\[email protected]@license-webpack-plugin\dist\ModuleProcessor.js:44:46)
    at ModuleProcessor.processFile (D:\me\angular\ngApp\node_modules\[email protected]@license-webpack-plugin\dist\ModuleProcessor.js:41:21)
    at fileCallback (D:\me\angular\ngApp\node_modules\[email protected]@license-webpack-plugin\dist\LicenseWebpackPlugin.js:107:61)
    at moduleCallback (D:\me\angular\ngApp\node_modules\[email protected]@license-webpack-plugin\dist\LicenseWebpackPlugin.js:114:21)
    at D:\me\angular\ngApp\node_modules\[email protected]@license-webpack-plugin\dist\LicenseWebpackPlugin.js:126:29
    at Array.forEach (<anonymous>)
    at emitCallback (D:\me\angular\ngApp\node_modules\[email protected]@license-webpack-plugin\dist\LicenseWebpackPlugin.js:92:32)
    at _err0 (eval at create (D:\me\angular\ngApp\node_modules\[email protected]@tapable\lib\HookCodeFactory.js:32:10), <anonymous>:19:1)
    at callback (D:\me\angular\ngApp\node_modules\[email protected]@copy-webpack-plugin\dist\index.js:77:17)
    at D:\me\angular\ngApp\node_modules\[email protected]@copy-webpack-plugin\dist\index.js:118:24
    at <anonymous>
(node:21768) 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:21768) [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.

在各种百度、谷歌、stack overfolw后解决方法:

(1)第一种解决办法:使用yarn代替cnpm安装依赖包

  然后使用yarn遇到了一连串的问题,解决方法和安装使用方法请参考我的另一篇博文:《yarn踩坑记录》

  最后 ng serve 成功运行:

D:\me\angular\ng-app>ng serve
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **

Date: 2018-10-10T02:12:20.302Z
Hash: 239e5b9b82b5dbe931da
Time: 10477ms
chunk {main} main.js, main.js.map (main) 10.7 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 227 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.22 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 15.6 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 3.28 MB [initial] [rendered]
i 「wdm」: Compiled successfully.

(2)第二种解决方法:使用npm 代替cnpm安装依赖包

D:\me\angular\ng-app>npm install

  个人来说还是推荐第一种使用yarn来安装依赖包,yarn的使用方法和npm大同小异;但是第二种使用npm安装的方式,在有vpn的条件下还是不错的,不然等待你的将会是一大堆安装失败、警告的报错信息。

猜你喜欢

转载自blog.csdn.net/WU5229485/article/details/82985492