Reputation: 809
This seems to be a semi-common error, but it's unclear to me what is causing it. I want to know what is causing this error and how can I resolve it.
Using NVM I have installed Node @latest (Version 17.4.0), which has installed npm's matching latest (v8.3.1).
PS C:\myRepo> node -v
v17.4.0
PS C:\myRepo> npm -v
8.3.1
PS C:\myRepo> nvm list
* 17.4.0 (Currently using 64-bit executable)
17.0.0
15.6.0
14.18.3
14.15.4
12.20.1
I then go to install a package dependency from npm and it gives me an error regardless of the package name:
PS C:\myRepo> npm install -g npm
npm ERR! Unexpected token '.'
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\yodama\AppData\Local\npm-cache\_logs\2022-01-25T16_38_44_607Z-debug-0.log
And we can see the full debug log:
0 verbose cli [
0 verbose cli 'C:\\Program Files\\nodejs\\node.exe',
0 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
0 verbose cli 'install',
0 verbose cli '-g',
0 verbose cli 'npm'
0 verbose cli ]
1 info using [email protected]
2 info using [email protected]
3 timing npm:load:whichnode Completed in 0ms
4 timing config:load:defaults Completed in 1ms
5 timing config:load:file:C:\Users\yodama\AppData\Roaming\nvm\v17.4.0\node_modules\npm\npmrc Completed in 3ms
6 timing config:load:builtin Completed in 3ms
7 timing config:load:cli Completed in 3ms
8 timing config:load:env Completed in 0ms
9 timing config:load:project Completed in 3ms
10 timing config:load:file:C:\Users\yodama\.npmrc Completed in 4ms
11 timing config:load:user Completed in 4ms
12 timing config:load:file:C:\Program Files\nodejs\etc\npmrc Completed in 0ms
13 timing config:load:global Completed in 0ms
14 timing config:load:validate Completed in 0ms
15 timing config:load:credentials Completed in 1ms
16 timing config:load:setEnvs Completed in 1ms
17 timing config:load Completed in 19ms
18 timing npm:load:configload Completed in 20ms
19 timing npm:load:setTitle Completed in 1ms
20 timing config:load:flatten Completed in 4ms
21 timing npm:load:display Completed in 7ms
22 verbose logfile C:\Users\yodama\AppData\Local\npm-cache\_logs\2022-01-25T16_38_44_607Z-debug-0.log
23 timing npm:load:logFile Completed in 13ms
24 timing npm:load:timers Completed in 0ms
25 timing npm:load:configScope Completed in 0ms
26 timing npm:load Completed in 42ms
27 verbose stack C:\Users\yodama\AppData\Roaming\nvm\v17.4.0\node_modules\npm\node_modules\libnpmfund:1
27 verbose stack ../workspaces/libnpmfund
27 verbose stack ^
27 verbose stack
27 verbose stack SyntaxError: Unexpected token '.'
27 verbose stack at Object.compileFunction (node:vm:352:18)
27 verbose stack at wrapSafe (node:internal/modules/cjs/loader:1026:15)
27 verbose stack at Module._compile (node:internal/modules/cjs/loader:1061:27)
27 verbose stack at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
27 verbose stack at Module.load (node:internal/modules/cjs/loader:975:32)
27 verbose stack at Function.Module._load (node:internal/modules/cjs/loader:822:12)
27 verbose stack at Module.require (node:internal/modules/cjs/loader:999:19)
27 verbose stack at require (node:internal/modules/cjs/helpers:102:18)
27 verbose stack at Object.<anonymous> (C:\Users\yodama\AppData\Roaming\nvm\v17.4.0\node_modules\npm\lib\utils\reify-output.js:16:38)
27 verbose stack at Module._compile (node:internal/modules/cjs/loader:1097:14)
28 verbose cwd C:\myRepo
29 verbose Windows_NT 10.0.22000
30 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "npm"
31 verbose node v17.4.0
32 verbose npm v8.3.1
33 error Unexpected token '.'
34 verbose exit 1
35 timing npm Completed in 262ms
36 verbose code 1
switching using nvm for windows to Node 14 fixes this issue:
PS C:\myRepo> nvm use 14.18.3
Now using node v14.18.3 (64-bit)
PS C:\myRepo> node -v
v14.18.3
PS C:\myRepo> npm -v
6.14.15
PS C:\myRepo> npm i -g @microsoft/rush
npm WARN deprecated @opentelemetry/[email protected]: Package renamed to @opentelemetry/api, see https://github.com/open-telemetry/opentelemetry-js
C:\Program Files\nodejs\rush -> C:\Program Files\nodejs\node_modules\@microsoft\rush\bin\rush
C:\Program Files\nodejs\rushx -> C:\Program Files\nodejs\node_modules\@microsoft\rush\bin\rushx
+ @microsoft/[email protected]
added 286 packages from 296 contributors in 26.69s
What is going wrong here? Is this an NVM issue, or a npm 8.x issue? I need to do testing in Node v17 for a specific bug, so just using the older versions of Node isn't a viable workaround.
Upvotes: 28
Views: 39165
Reputation: 21
I faced same issue and resolved it by upgrading nvm version to 1.1.11 https://github.com/coreybutler/nvm-windows/releases
Then,
nvm uninstall <broken_version>
and
nvm install <broken_version>
Upvotes: 0
Reputation: 11
For windows: visit:enter link description here download 'nvm-update.exe' and update NVM to 1.1.10 uninstall your old node version, and reinstall node.
Upvotes: 0
Reputation: 172
I was able to get past this issue on my machine, originally posted steps here
It appears that when you install newer versions of Node via nvm
you need to make sure you do so in an Administravtive console. If you don't, it is failing to install npm's
packages and there are a bunch of broken lib files.
I was getting these issues with nvm-windows
, the fix for me was to
nvm uninstall {brokenNodeVersion}
nvm install {brokenNodeVersion}
I was able to tell what versions of node were broken on my machine by looking at the libnpmfund
folder under the C:\Users\{user}\AppData\Roaming\nvm\v{brokenNodeVersion}\node_modules\npm\node_modules\libnpmfund
and there would be a bunch of broken files with no extension. The contents of the files would just be one line like ..\packageName
After re-installing with an admin console I see the broken files are gone and the folder looks like:
Upvotes: 0
Reputation: 143
I had a similar issue and I solved it by using node version 16.13.2
Upvotes: 0
Reputation: 11
I had the same problem and I solved it by bringing the node version from 16.17.0 to 16.0.0.
[npm version -> 7.10.0]
nvm install 16.0.0
nvm use 16.0.0
npm install
STACKTACE:
verbose stack SyntaxError: Unexpected token '.'
33 verbose stack at Object.compileFunction (node:vm:360:18)
33 verbose stack at wrapSafe
(node:internal/modules/cjs/loader:1055:15)
33 verbose stack at Module._compile
(node:internal/modules/cjs/loader:1090:27)
33 verbose stack
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
33 verbose stack at Module.load (node:internal/modules/cjs/loader:1004:32)
33 verbose stack at Function.Module._load (node:internal/modules/cjs/loader:839:12)
33 verbose stack at Module.require (node:internal/modules/cjs/loader:1028:19)
33 verbose stack at require (node:internal/modules/cjs/helpers:102:18)
33 verbose stack at Object. (C:\Users<name>\AppData\Roaming\nvm\v16.17.0\node_modules\npm\lib\utils\reify-output.js:16:38)
33 verbose stack at Module._compile (node:internal/modules/cjs/loader:1126:14)
Upvotes: 1
Reputation: 31
Just do: nvm use [lower version] if you are using node version 17.9.0 than just downgrade the version and it will work.
Upvotes: 0
Reputation: 81
this solved my issue
Upvotes: 8
Reputation: 450
Download and install the update version of NVM Windows and run it. Then, download an LTS version of node
Upvotes: 2
Reputation: 77
use a lower version of node.
nvm list
-> to see the installed node versions.
nvm use <-version number->
run npm install
again.
Upvotes: 5
Reputation: 555
Update the NVM-Windows to the newest version, which is by now
1.1.9
They've had fixed this issue, Workspace folder must be symlink.
The issue goes with NVM-Windows not NPM
Upvotes: 44