`npx -p .. -c ''` fails without package.json present in working directory
codfish opened this issue · comments
What / Why
npx create-react-app test
works as expected butnpx -p create-react-app -c "create-react-app test"
will fail with the following error:
→ npx -p create-react-app -c "create-react-app test"
Command failed: /Users/codonnell/.nvm/versions/node/v12.16.1/bin/node /Users/codonnell/.nvm/versions/node/v12.16.1/lib/node_modules/npx/node_modules/npm/bin/npm-cli.js run env --parseable
npm ERR! path /Users/codonnell/Sites/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/Users/codonnell/Sites/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/codonnell/.npm/_logs/2020-04-12T16_16_14_116Z-debug.log
This is a contrived example to display the issue. The real issue arose for me when attempting to run a yeoman generator, which requires 2 dependencies, hence the need to run with -p
.
npx -p yo -p generator-codfish -c 'yo codfish'
Details
codonnell in ~/Sites
→ pwd
/Users/codonnell/Sites
- using nvm to install node (and in turn npm/npx)
→ nvm --version
0.35.0
→ node -v
v12.16.1
→ npm -v
6.13.4
→ npx -v
10.2.2
When
- Every time, consistently
Where
- local machine
How
Current Behavior
- Fails immediately with above error
When I run the same command in directory with a package.json
it works as expected. It does NOT mutate the package.json and doesn't install any modules in that directory, which is to be expected. However it's still failing unless you actually have a package.json file in the cwd
Steps to Reproduce
- Run npx with -p & -c options to run a cli instead of just running directly
- Run this inside of a directory without a package.json
Expected Behavior
- Expect it to be able to just install dependencies the way npx normally would. Then run the command
- Should not fail because it doesn't find a package.json in the working directory
Who
- n/a
References
- n/a
I had a similar problem with yeoman and as it turned out, it was due to ignoring node_modules
in the generator
this.fs.copy(from, to, {
globOptions: {
dot: true,
ignore: ['**/node_modules/**', '**/build/**'], // <- problem was here
},
})
i got error Trying to copy from a source that does not exist
BUT if the folder with this generator-project was downloaded locally, everything worked
I get the same problem when I use npx -c .... without a package.json
I assume it's caused by this code line:https://github.com/npm/npx/blob/latest/index.js#L127