TypeScript error TS5014: Unexpected token u in JSON at position 0

I would like to put in that you also see this error when you forgot to add 'typescript' as a dependency.

npm install typescript

should fix that.

Note that this dependency is present in the package.json in the question.


There could be a bunch of things that can go wrong when saving a file that would prevent correct parsing. I usually elect to not deal with it by renaming the file to tsconfig.json.backup or something, then invoking tsc --init to generate a known good file. You can then transfer your specific configuration into the newly generated tsconfig.json file, uncommenting the parts you care about.

If it persists after that, it could be an actual bug in the TypeScript version you're on.


If you look at the error message carefully, you can see the reason for the failure. The command line that was formed to run tsc is looking at the wrong directory. It was looking at <myprojloc>/tsconfig.json/ instead of <myprojloc>/. See how tsconfig.json is repeated twice in the error?

error TS5014: Failed to parse file '<myprojloc>/tsconfig.json/tsconfig.json': Unexpected token u in JSON at position 0.

Running npm install typescript --save-dev worked for me, but I can see how editing the task and specifying the command to look in the right directory for tsconfig.json would solve the problem too.