Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] When installing a git dependency, prepare script can see dev dependencies, prepack script can not #1229

Closed
trusktr opened this issue May 1, 2020 · 6 comments
Labels
Bug thing that needs fixing Release 6.x work is associated with a specific npm 6 release

Comments

@trusktr
Copy link

trusktr commented May 1, 2020

What

When a project has a dependency from git that has a prepack script (instead of a prepare script), the prepack step of the git dependency fails because dev dependencies are not present to the prepack script.

This issue is not happening if the git dependencies use prepare instead of prepack.

When

Whenever I run npm install in my project, and the git dependencies have a prepack script instead of a prepare script.

Where

Git dependencies. I haven't made a public reproduction yet.

How

Publish a package in a git repo. Make sure it uses prepack in its package.json to define the steps needed to build the projects into usable state.

Current Behavior

My project's npm install fails because a git dependency's prepack script fails to find the commands that it uses.

If I fork the git dependency and modify it to use prepare, then things work great.

Steps to Reproduce

  • Publish a package as a git repo
  • Make sure the package uses prepack to run the steps needed to build it (f.e. build from src/ to dist/). Make sure this prepack script relies on executables installed as dev dependencies.
  • Make another project that depends on the dependency from git.
  • Run npm install in the project that depends on the git dependency.
  • The prepack step in the git dependency should fail.

Expected Behavior

prepack should work the same as prepare in this regard.

Who

Me, but hopefully I'm not the only one!

@trusktr
Copy link
Author

trusktr commented May 1, 2020

In my case, a git dependency of my project has this in package.json:

  "scripts": {
    "build": "gulp copyAssets && npm run compile"
    "prepack": "npm run build"
    // ...
  },
  "devDependencies": {
    "gulp": "^4.0.2",
    "gulp-cli": "^2.2.0",
    // ...
  }

and when my project is installing this dependency, it fails with output like this:

> [email protected] prepack /home/trusktr/.npm/_cacache/tmp/git-clone-d072021d
> npm run build


> [email protected] build /home/trusktr/.npm/_cacache/tmp/git-clone-d072021d
> gulp copyAssets && npm run compile

sh: gulp: command not found

However when I fork that dependency and make it use prepare so that package.json has

  "scripts": {
    "build": "gulp copyAssets && npm run compile"
    "prepare": "npm run build" // <-------------- HERE
    // ...
  },
  "devDependencies": {
    "gulp": "^4.0.2",
    "gulp-cli": "^2.2.0",
    // ...
  }

then everything works perfectly.

@trusktr
Copy link
Author

trusktr commented May 12, 2020

This bit me again. It's a tricky problem because some alternative tools to NPM only support prepack and not prepare.

This means if we have prepare in package.json, it works with NPM but not the other tools. If we have prepack in package.json, it works with other tools but not with NPM.

This makes it difficult to make packages consumable from git while being compatible with all tools in the ecosystem.

Would it be fine to add dev dependency support to prepack?

@trusktr
Copy link
Author

trusktr commented Jun 7, 2020

Hellooooooooooooooooo. Does anyone triage NPM issues?

@kimamula
Copy link

kimamula commented Sep 26, 2020

@trusktr Which version of npm CLI are you using? I found that both of prepare and prepack are not working as expected with npm CLI v6 and v7 beta.

EDIT: My bad, the way I confirmed the behavior was not correct. prepare is working fine with npm CLI v6 as written in the description of this issue.

v6.14.8

  • prepare: devDependencies are not installed and prepare script is not executeddevDependencies are installed and prepare script is executed (expected behavior)
  • prepack: devDependencies are NOT installed but prepack script is executed

v7.0.0-beta.12

  • prepare: devDependencies are NOT installed but prepare script is executed
  • prepack: devDependencies are NOT installed and prepack script is NOT executed

@darcyclarke darcyclarke added Bug thing that needs fixing Release 6.x work is associated with a specific npm 6 release labels Oct 6, 2020
@darcyclarke darcyclarke added this to the OSS - Sprint 18 milestone Oct 6, 2020
@darcyclarke darcyclarke removed this from the OSS - Sprint 18 milestone Oct 19, 2020
@OmgImAlexis
Copy link

Are there any work arounds or should we just avoid npm v7 if we're using git installs?

Currently everything I try to use is failing because devDeps are missing. Using npm v7.0.8 myself.

@darcyclarke
Copy link
Contributor

npm v6 is no longer in active development; We will continue to push security releases to v6 at our team's discretion as-per our Support Policy.

If your bug is preproducible on v7, please re-file this issue using our new issue template.

If your issue was a feature request, please consider opening a new RRFC or RFC. If your issue was a question or other idea that was not CLI-specific, consider opening a discussion on our feedback repo

Closing: This is an automated message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Release 6.x work is associated with a specific npm 6 release
Projects
None yet
Development

No branches or pull requests

4 participants