[BUG] `prepare` and `prepack` scripts are not handled as documented when installing a git dependency
Problem
Current Behavior: I tested installing a git dependency which has either `prepare` or `prepack` script with npm CLI v7.0.0-beta.12 and confirmed the following behaviors. - a package with a `prepare` script: `devDependencies` are NOT installed but the `prepare` script is executed - a package with a `prepack` script: `devDependencies` are NOT installed and the `prepack` script is NOT executed Expected Behavior: - a package with a `prepare` script: `devDependencies` are installed and the `prepare` script is executed - a package with a `prepack` script: `devDependencies` are installed and the `prepack` script is executed - Though I've not found any document saying that `devDependencies` are installed when installing a git dependency with a `prepack` script and actually they are not installed even when npm CLI v6 is used, I believe npm should install them since running a `prepack` script without installing `devDependencies` does not make sense. Steps To Reproduce: `prepare`: [code block] [code block] `prepack`: [code block] [code block] -> `tsc` should generate `index.js` file, but it's not generated. Environment: - OS: macOS 10.15.6 - Node: 12.18.3 - npm: 7.0.0-beta.12
Error Output
Error: no test specified\" && exit 1",
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Fix npm handling of prepare and prepack scripts for git dependencies
The current behavior of npm CLI v7.0.0-beta.12 does not install devDependencies when executing prepare and prepack scripts for git dependencies. This is inconsistent with expected behavior where devDependencies should be available for these scripts, particularly since they may be necessary for building or preparing the package.
Awaiting Verification
Be the first to verify this fix
- 1
Update npm to the latest stable version
Ensure that you are using the latest stable version of npm, as this may contain fixes for the handling of prepare and prepack scripts.
bashnpm install -g npm@latest - 2
Modify package.json to include a build step
Add a build step in your package.json that explicitly installs devDependencies before running the prepare or prepack scripts. This can be done by chaining commands in the scripts section.
json{ "scripts": { "prepare": "npm install && your-prepare-command", "prepack": "npm install && your-prepack-command" } } - 3
Test the installation of the git dependency
Run the installation command for the git dependency to verify that devDependencies are installed and the scripts execute correctly.
bashnpm install git+https://github.com/your-repo.git - 4
Check generated files
After installation, verify that the expected files (e.g., index.js) are generated correctly. This confirms that the prepare or prepack scripts ran successfully with access to devDependencies.
bashls -l index.js - 5
Report any remaining issues
If the problem persists, gather logs and report the issue to the npm GitHub repository for further investigation.
bashnpm install git+https://github.com/your-repo.git --verbose
Validation
Confirm that the devDependencies are installed and that the prepare and prepack scripts execute without errors, resulting in the expected output files being generated.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep