简体   繁体   中英

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. 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

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

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?

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. So, removed and reinstalled webpack. Now ng test command and ng s works fine.

after restarting my system this issue got resolved. I don't know why but it worked

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM