'Unexpected token '.' when run create-react-app
I am trying to create a new React app using this command on Windows using Node 16.14
npx create-react-app my-app
But it fails with this error npm ERR! Unexpected token '.'
From the log, this is the stack trace:
28 verbose stack C:\ProgramData\nvm\v16.14.0\node_modules\npm\node_modules\libnpmexec:1
28 verbose stack ../workspaces/libnpmexec
28 verbose stack ^
28 verbose stack
28 verbose stack SyntaxError: Unexpected token '.'
28 verbose stack at Object.compileFunction (node:vm:352:18)
28 verbose stack at wrapSafe (node:internal/modules/cjs/loader:1032:15)
28 verbose stack at Module._compile (node:internal/modules/cjs/loader:1067:27)
28 verbose stack at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
28 verbose stack at Module.load (node:internal/modules/cjs/loader:981:32)
28 verbose stack at Function.Module._load (node:internal/modules/cjs/loader:822:12)
28 verbose stack at Module.require (node:internal/modules/cjs/loader:1005:19)
28 verbose stack at require (node:internal/modules/cjs/helpers:102:18)
28 verbose stack at Object.<anonymous> (C:\ProgramData\nvm\v16.14.0\node_modules\npm\lib\commands\exec.js:1:17)
28 verbose stack at Module._compile (node:internal/modules/cjs/loader:1103:14)
Can you please tell me what is the issue?
Solution 1:[1]
Try to downgrade npm version. I had this same, on 16.14.0. I recommend nvm for changing node version. For example: nvm install 14.18.1 nvm use 14.18.1
Solution 2:[2]
If you're using nvm, upgrading to the latest version of nvm (1.1.9 at the time of writing), uninstalling the node version and reinstalling it fixes the issue.
Solution 3:[3]
The error is in the debuglog.js file, line 10, located in the path:
C:\Program Files\nodejs\node_modules\npm\node_modules\debuglog\debuglog.js:10
The error is quite simple, to fix it change the command that is there as follows if (!debugs[set?)
to if (!debugs[set])
and save as administrator.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Marcin Kot |
Solution 2 | baywet |
Solution 3 | Ícaro Bomfim Teles |