Skip to content
This repository has been archived by the owner on Apr 7, 2021. It is now read-only.

npx -p .. -c '' fails without package.json present in working directory #53

Open
codfish opened this issue Apr 12, 2020 · 2 comments
Open

Comments

@codfish
Copy link

codfish commented Apr 12, 2020

What / Why

npx create-react-app test works as expected but npx -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
@itslooklike
Copy link

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

@mofterdinger
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants