简体   繁体   English

ng test 和 ng serve 失败,并显示“发生未处理的异常:无效或意外的令牌”

[英]ng test and ng serve fails with "An unhandled exception occurred: Invalid or unexpected token"

In my Angular8 application, both ng serve and ng test was working fine till yesterday.在我的 Angular8 应用程序中,直到昨天,ng serve 和 ng test 都运行良好。 But today, both command fails with error.但是今天,这两个命令都失败并出现错误。

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 file 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)

When I tried npm install/update, it fails.当我尝试 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)

Can someone advise what is the issue and how to make ng s and ng test run fine?有人可以建议是什么问题以及如何使 ng s 和 ng 测试正常运行吗?

node_modules此错误的最可能原因是您的node_modules文件夹配置不正确,可能是您从其他来源下载了项目以及node_modules ,因此需要重新安装软件包

sudo rm -rf node_modules

sudo npm i

After removing and reinstalling iconv-lite package, when running ng test command, now the error in angular-errors.log file indicated webpack library.删除并重新安装 iconv-lite 包后,在运行 ng test 命令时,现在 angular-errors.log 文件中的错误表示 webpack 库。 So, removed and reinstalled webpack.所以,删除并重新安装 webpack。 Now ng test command and ng s works fine.现在 ng test 命令和 ng s 工作正常。

after restarting my system this issue got resolved.重新启动我的系统后,这个问题得到了解决。 I don't know why but it worked我不知道为什么,但它有效

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行 ng serve 发生未处理的异常 - Unhandled exception occurred running ng serve 使用 ng serve 在 angular 中发生未处理的异常 - An unhandled exception occurred in angular using ng serve 发生未处理的异常:无效或意外的令牌 - An unhandled exception occurred: Invalid or unexpected token Angular cli 显示错误“发生未处理的异常:没有项目支持‘测试’目标。” 运行 ng test 或 ng serve 命令时 - Angular cli showing error "An unhandled exception occurred: No projects support the 'test' target." when running ng test or ng serve command 发生未处理的异常:在工作空间中未设置配置&#39;es5&#39;。 ng在角度8中投放es5 - An unhandled exception occurred: Configuration 'es5' is not set in the workspace. ng serve in angular 8 for es5 当我执行ng serve -o时,发生未处理的异常:ts.createNodeArray不是函数 - When I am doing ng serve -o then getting an unhandled exception occurred: ts.createNodeArray is not a function angular ng serve 命令抛出错误:发生未处理的异常:项目不存在 - angular ng serve command throws error: An unhandled exception occurred: Project does not exist Angular ng 服务导致:发生未处理的异常:未在工作区中设置配置“生产” - Angular ng serve leads to: An unhandled exception occurred: Configuration 'production' is not set in the workspace 发生未处理的异常:无法使用 ng serve 找到模块“@angular/compiler-cli” - An unhandled exception occurred: Cannot find module '@angular/compiler-cli' with ng serve ng test - 意外的令牌&#39;const&#39; - ng test - unexpected token 'const'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM