Angular CLI stopped working - Unexpected token {
Solution 1
It is now working after
- Updating node as suggested by Kind user
- Updating Angular CLI https://github.com/angular/angular-cli#updating-angular-cli
For my old project to work after these changes I had to do the following (some of the steps are from the link above).
- rmdir /s node_modules
- rmdir /s dist
- npm install --save-dev @angular/cli@latest
- npm install
- ng update
- Update package.json as suggested here Getting error on ng serve: ERROR in Cannot read property 'listLazyRoutes' of undefined
- npm install (again)
This update worked for most of my projects but I still have an issue with one
ng serve
patterns.map is not a function
TypeError: patterns.map is not a function
at GlobCopyWebpackPlugin.apply (C:\Users\jhertz\Workspaces\eclipsekatujo\ibi\src\app\node_modules\@angular\cli\plugins\glob-copy-webpack-plugin.js:25:29)
at Compiler.apply (C:\Users\jhertz\Workspaces\eclipsekatujo\ibi\src\app\node_modules\tapable\lib\Tapable.js:306:16)
at webpack (C:\Users\jhertz\Workspaces\eclipse-katujo\ibi\src\app\node_modules\webpack\lib\webpack.js:32:19)
at Class.run (C:\Users\jhertz\Workspaces\eclipse-katujo\ibi\src\app\node_modules\@angular\cli\tasks\serve.js:63:27)
at checkExpressPort.then.then (C:\Users\jhertz\Workspaces\eclipse-katujo\ibi\src\app\node_modules\@angular\cli\commands\serve.js:84:26)
at process._tickCallback (internal/process/next_tick.js:103:7)
The above error got solved by updating the angular-cli.json in the project folder.
== Old ==
"assets": "assets",
== New ==
"assets": ["assets"]
Solution 2
Experienced the same problem but I managed to solve it by deleting the node_modules folder and the yarn.lock file. I then re-installed the packages (using yarn) and changed the node version to >=8.9.0, and it worked.
Related videos on Youtube
jhertz
Updated on June 27, 2022Comments
-
jhertz almost 2 years
I used Angular CLI to create projects for a while and it was working fine. But when I tried to create a new project today I got an error when trying to serve it.
ng serve Unexpected token { SyntaxError: Unexpected token { at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:373:25) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) ...
Here is the full stack trace http://pastebin.com/71qU3G64
If I delete the node_modules directory and copy it from an old project it works, but that is not a long term solution.
-
kind user over 7 yearsUse
ng -v
andnpm -v
in the console and post it here. -
jhertz over 7 yearsng -v Unexpected token { npm 3.10.9 pastebin.com/JyHmY2JR
-
kind user over 7 yearsIf even the
ng -v
command doesn't work for you, I suggest you to reinstallangular-cli
. -
jhertz over 7 yearsIt seems like the first issue is impacting the ng -v problem. If I restart the cmd I get ng -v angular-cli: 1.0.0-beta.19-3 node: 4.5.0 os: win32 x64
-
kind user over 7 yearsFine. Update your
node
first to the version of 6.9 or higher. -
Aravind over 7 yearstry reinstalling the node_modules
-
jhertz over 7 yearsUpdated node which got rid of the original problem, but now I get a error with Jasmine instead, please see pastebin.com/CqG5Les2
-