angular - ng test 和 ng serve 失败,错误为 "An unhandled exception occurred: Invalid or unexpected token"

标签 angular

在我的 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 ,所以需要重新安装软件包
sudo rm -rf node_modulessudo npm i

关于angular - ng test 和 ng serve 失败,错误为 "An unhandled exception occurred: Invalid or unexpected token",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60038701/

相关文章:

Angular2 和 webpack,组件需要 sass 中断单元测试

javascript - 如何在 Angular4 中实现 ngFor 回调?

angular - 如何为 ASP.NET Core Angular 应用程序设置默认端口

javascript - 我可以在常规 JS 中监听 AngularJS 中抛出的事件吗(在 Angular 之外?)

Angular 模块从 es6 到 commonJs 结果

javascript - 添加提供程序@NgModule 时出现 Angular2 "No provider for Service!"错误

Angular2-http ://localhost:4200/being appended with api call why?

angular - 覆盖 Angular-5 中库组件的 css 类属性

javascript - 使用 Chrome headless 和 Karma 挂起的 Angular 单元测试

javascript - 生产中的 Angular 应用程序路由错误