create-adapter
create-adapter copied to clipboard
npx doesn't work at all on Windows if spaces are in the path to npm-cache
If spaces are in the path to npm-cache you always get the following error when executing npx:
C:\dev\adapter>npx @iobroker/create-adapter
npm ERR! code ENOLOCAL
npm ERR! Could not install from "Files\iobroker\SmartHome17\env\npm-cache\_npx\2772" as it does not contain a package.json file.
In this case the path to npm-cache was 'C:\Program Files\iobroker\SmartHome17\env\npm-cache'.
More logging:
1 verbose cli [ 'C:\\Program Files\\iobroker\\SmartHome17\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\iobroker\\SmartHome17\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'install',
1 verbose cli '@iobroker/create-adapter@latest',
1 verbose cli '--global',
1 verbose cli '--prefix',
1 verbose cli 'C:\\Program',
1 verbose cli 'Files\\iobroker\\SmartHome17\\env\\npm-cache\\_npx\\8336',
2 info using [email protected]
3 info using [email protected]
7 silly fetchPackageMetaData error for file:Files\iobroker\SmartHome17\env\npm-cache\_npx\8336 Could not install from "Files\iobroker\SmartHome17\env\npm-cache\_npx\8336" as it does not contain a package.json file.
12 verbose stack Error: ENOENT: no such file or directory, open 'C:\dev\adapter\Files\iobroker\SmartHome17\env\npm-cache\_npx\8336\package.json'
14 verbose Windows_NT 10.0.17134
15 verbose argv "C:\\Program Files\\iobroker\\SmartHome17\\nodejs\\node.exe" "C:\\Program Files\\iobroker\\SmartHome17\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "@iobroker/create-adapter@latest" "--global" "--prefix" "C:\\Program" "Files\\iobroker\\SmartHome17\\env\\npm-cache\\_npx\\8336" "--loglevel" "error" "--json"
NOTE: Why the weird escape condition? Because the child.spawn npm always runs in shell mode when on Windows (it's the default, to prevent weird behavior). That means that arguments to npm need to be escaped (but as strings, not as paths). The regular unix invocation doesn't need escaping, because it doesn't run in shell mode.
npx GitHub issues: https://github.com/zkat/npx/issues/146 - workaround, not solved, closed https://github.com/zkat/npx/issues/100 - open, since July 2017 https://github.com/zkat/npx/issues/223 - open, is npx project dead? https://github.com/npm/npx/issues/6
Solution: https://github.com/zkat/npx/pull/181 - open since May 2018
I've mentioned this in the README, since the PR doesn't look like it will be merged anytime soon.
https://github.com/npm/npx/issues/30#issuecomment-580816679
Seems we have to wait until at least the 2nd half of 2020
this worked for me - https://stackoverflow.com/a/46871748/12581294
Sadly this is nothing we can do in the script. The user has to open the folder in "short mode" before executing create-adapter.