[英]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.