[英]ng test and ng serve fails with "An unhandled exception occurred: Invalid or unexpected token"
在我的 Angular8 應用程序中,直到昨天,ng serve 和 ng test 都運行良好。 但是今天,這兩個命令都失敗並出現錯誤。
An unhandled exception occurred: Invalid or unexpected token See "C:\Users\Username\AppData\Local\Temp\ng-jcwQWX\angular-errors.log" for further details.
angular-errors.log 文件
[error] C:\Users\Username\Documents\GWM\GWM-Front-end\node_modules\webpack\lib\node\NodeMainTemplatePlugin.js:2
SyntaxError: Invalid or unexpected token
at compileFunction (<anonymous>)
at Module._compile (internal/modules/cjs/loader.js:892:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:849:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (C:\Users\Username\Documents\GWM\GWM-Front-end\node_modules\webpack\lib\node\NodeTemplatePlugin.js:8:32)
at Module._compile (internal/modules/cjs/loader.js:956:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:849:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (C:\Users\Username\Documents\GWM\GWM-Front-end\node_modules\@ngtools\webpack\src\resource_loader.js:16:28)
at Module._compile (internal/modules/cjs/loader.js:958:30)
當我嘗試 npm install/update 時,它失敗了。
C:\Users\Username\AppData\Roaming\npm\node_modules\npm\node_modules\iconv-lite\lib\streams.js:1 {��{��{��{��{��{��{��{��{��{��{��{��{��{��{��d]��KC��RJ��VM��XO��YP��YP��YP��YP��YP��YP��YP��YP��YP��YP��YP��YP��YP��YP��YP��YP��A<Y
SyntaxError: Invalid or unexpected token
at Module._compile (internal/modules/cjs/loader.js:892:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:849:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (C:\Users\Username\AppData\Roaming\npm\node_modules\npm\node_modules\iconv-lite\lib\index.js:144:9)
at Module._compile (internal/modules/cjs/loader.js:956:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
有人可以建議是什么問題以及如何使 ng s 和 ng 測試正常運行嗎?
您node_modules
此錯誤的最可能原因是您的node_modules
文件夾配置不正確,可能是您從其他來源下載了項目以及node_modules
,因此需要重新安裝軟件包
sudo rm -rf node_modules
sudo npm i
刪除並重新安裝 iconv-lite 包后,在運行 ng test 命令時,現在 angular-errors.log 文件中的錯誤表示 webpack 庫。 所以,刪除並重新安裝 webpack。 現在 ng test 命令和 ng s 工作正常。
重新啟動我的系統后,這個問題得到了解決。 我不知道為什么,但它有效
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.