Repository navigation
Closed
Labels
Description
On windows 11 I can't use npm with node 17.4.0 when I explicitly ask to install npm 8.3.1 (which is shipped with this node version by default):
C:\Users\maxim\my-project>python -m nodeenv nodeenv --node=17.4.0 --npm=8.3.1 --with-npm
* Install prebuilt node (17.4.0) ..... done.
symbolic link created for nodeenv\Scripts\nodejs.exe <<===>> node.exe
* Install npm.js (8.3.1) ...
C:\Users\maxim\my-project>nodeenv\Scripts\activate.bat
(nodeenv) C:\Users\maxim\my-project>node -v
v17.4.0
(nodeenv) C:\Users\maxim\my-project>npm -v
8.3.1
(nodeenv) C:\Users\maxim\my-project>npm install something
npm ERR! Unexpected token '.'
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\maxim\AppData\Local\npm-cache\_logs\2022-06-23T12_13_38_115Z-debug-0.log
(nodeenv) C:\Users\maxim\my-project>Here's a complete log:
0 verbose cli [
0 verbose cli 'C:\\Users\\maxim\\my-project\\nodeenv\\Scripts\\node.exe',
0 verbose cli 'C:\\Users\\maxim\\my-project\\nodeenv\\Scripts\\node_modules\\npm\\bin\\npm-cli.js',
0 verbose cli 'install',
0 verbose cli 'something'
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\maxim\my-project\nodeenv\Scripts\node_modules\npm\npmrc Completed in 1ms
6 timing config:load:builtin Completed in 1ms
7 timing config:load:cli Completed in 1ms
8 timing config:load:env Completed in 1ms
9 timing config:load:file:C:\Users\maxim\my-project\.npmrc Completed in 2ms
10 timing config:load:project Completed in 3ms
11 timing config:load:file:C:\Users\maxim\.npmrc Completed in 1ms
12 timing config:load:user Completed in 1ms
13 timing config:load:file:C:\Users\maxim\my-project\nodeenv\Scripts\etc\npmrc Completed in 0ms
14 timing config:load:global Completed in 0ms
15 timing config:load:validate Completed in 1ms
16 timing config:load:credentials Completed in 1ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 12ms
19 timing npm:load:configload Completed in 12ms
20 timing npm:load:setTitle Completed in 0ms
21 timing config:load:flatten Completed in 2ms
22 timing npm:load:display Completed in 3ms
23 verbose logfile C:\Users\maxim\AppData\Local\npm-cache\_logs\2022-06-23T12_13_38_115Z-debug-0.log
24 timing npm:load:logFile Completed in 6ms
25 timing npm:load:timers Completed in 0ms
26 timing npm:load:configScope Completed in 0ms
27 timing npm:load Completed in 23ms
28 verbose stack C:\Users\maxim\my-project\nodeenv\Scripts\node_modules\npm\node_modules\libnpmfund:1
28 verbose stack ../workspaces/libnpmfund
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:1026:15)
28 verbose stack at Module._compile (node:internal/modules/cjs/loader:1061:27)
28 verbose stack at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
28 verbose stack at Module.load (node:internal/modules/cjs/loader:975: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:999:19)
28 verbose stack at require (node:internal/modules/cjs/helpers:102:18)
28 verbose stack at Object.<anonymous> (C:\Users\maxim\my-project\nodeenv\Scripts\node_modules\npm\lib\utils\reify-output.js:16:38)
28 verbose stack at Module._compile (node:internal/modules/cjs/loader:1097:14)
29 verbose cwd C:\Users\maxim\my-project
30 verbose Windows_NT 10.0.22000
31 verbose argv "C:\\Users\\maxim\\my-project\\nodeenv\\Scripts\\node.exe" "C:\\Users\\maxim\\my-project\\nodeenv\\Scripts\\node_modules\\npm\\bin\\npm-cli.js" "install" "something"
32 verbose node v17.4.0
33 verbose npm v8.3.1
34 error Unexpected token '.'
35 verbose exit 1
36 timing npm Completed in 267ms
37 verbose code 1
38 error A complete log of this run can be found in:
38 error C:\Users\maxim\AppData\Local\npm-cache\_logs\2022-06-23T12_13_38_115Z-debug-0.log
Here's a very similar issue with nvm4w: nvm-windows/nvm#814
This works:
python -m nodeenv nodeenv --node=17.4.0
npm install -g [email protected]
npm install something
Activity
Maxim-Mazurok commentedon Jun 24, 2022
Another example: node 18.3.0 and npm 8.3.1.
Doesn't work when installed using nodeenv, but if I install node using nodeend, activate env, then run
npm i -g [email protected]- it works fine.vitorgamer58 commentedon Aug 20, 2022
The same here with node 16.14.2
I've changed my node version with nvm to 16.12.0 and the problem was fixed.
cjablonski76 commentedon Mar 7, 2023
Posted what fixed this for me here:
nvm-windows/nvm#814 (comment)
ekalinin commentedon Sep 19, 2026
I think I can pin down the root cause here, and it is not node or npm version specific.
install_npm_windownloads the source repository of npm, not the published npm package:In that repo the npm workspaces are linked into
node_modulesby symlink. A GitHub zip archive stores a symlink as a regular file whose contents are the link target, and Python'szipfile.extractalldoes not restore it as a link.cli-8.3.1.ziphas 12 such entries, all undernode_modules/, including exactly the one from your stack trace:So after extraction
node_modules/libnpmfundis a one line text file containing../workspaces/libnpmfund, andrequire()-ing it fails on the first character of that text. That is precisely what the log says:It also explains why
npm i -g [email protected]inside the env works: that installs the published package, which has no symlinks.Suggested fix
Fetch the registry tarball instead of the GitHub source archive. Numbers I measured today:
github.com/npm/cli/archive/v8.3.1.zipregistry.npmjs.org/npm/-/npm-8.3.1.tgzgithub.com/npm/cli/archive/v11.6.2.zipregistry.npmjs.org/npm/-/npm-11.6.2.tgzThe tarball already ships everything
install_npm_wincopies out:package/bin/npm,package/bin/npm.cmd,package/bin/npm-cli.js(andnpx,npx.cmd).Three more things it fixes along the way:
--with-npmwith the default--npm=latestcurrently 404s, because the URL becomes.../archive/vlatest.zip. The registry resolves it directly:registry.npmjs.org/npm/latestgivesdist.tarball.Scripts\node_modules\npm; 89 chars leaves about 144. Most of that depth comes fromworkspaces/arborist/test/fixtures/..., test fixtures that have no business being in an installed npm anyway.raw.githubusercontent.comdownload ofbin/npmin the Cygwin branch becomes unnecessary, sincepackage/bin/npmis in the tarball.The symlink hazard is not hypothetical for current versions either:
zipfile.extractallwill keep flattening any symlink npm reintroduces, whereas the published tarball has none by construction.fix(nodeenv): install npm from the registry tarball on Windows
chore(ci): smoke-test --with-npm on windows-latest