npm / npm/cli

[BUG] Workspaces: 'Prepare: build' leads to error on npm install in base directory

Open
#3,972 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Needs Triage Release 8.x
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

Is there an existing issue for this?
  • I have searched the existing issues
Current Behavior

base-dir
packages/
package1/
package.json -> dependency: package2
package2/
...
package.json
workdir: ["packages/*"]

I have prepare scripts in each package which should build the package-project. On npm install in base directory npm install of each package will be run and therefore also the prepare scripts. At this point it seems though that the dependencies are not resolved correctly leading to an error on npm install and therefore dismissing further installations. The missing dependencies are locally installed in the node_modules directory of the packages. Therefore this should not lead to an error.

Npm install, npm run build, npm run prepare work fine from the package´s directory.

Might it be that the npm run prepare build is not run with cwd: package? Or how does npm install resolve the dependencies and dependency versions of each package. For some packages it seems that different versions of dependend packages are available but not the local installed dependency of the package.

This might be correlated with a few other bug reports.

Example error message
SonarQubePredecessorsQuantifier/cache/cache.ts: Cannot find module: This module is locally installed in the package´s node_modules directory. Npm install, npm build works fine with cwd: package.
npm ERR! code 2 npm ERR! path C:\ma-implementation-3\implementation\packages\bugFinder-commitPath-quantifier-sonarqubePredecessors npm ERR! command failed npm ERR! command C:\Windows\system32\cmd.exe /d /s /c npm run build npm ERR! > bugfinder-commitpath-quantifier-sonarqubepredecessors@1.1.5 build npm ERR! > npm run clean && tsc --project . npm ERR! npm ERR! npm ERR! > bugfinder-commitpath-quantifier-sonarqubepredecessors@1.1.5 clean npm ERR! > rimraf ./dist npm ERR! npm ERR! src/sonarQubePredecessorsQuantifier/cache/cache.ts(3,36): error TS2307: Cannot find module 'bugfinder-commitpath-quantifier-sonarqube' or its corresponding type declarations. npm ERR! src/sonarQubePredecessorsQuantifier/measurement/Elements.ts(1,23): error TS2307: Cannot find module 'bugfinder-commitpath-quantifier-sonarqube' or its corresponding type declarations. npm ERR! src/sonarQubePredecessorsQuantifier/measurement/SonarQubePredecessorMeasurement.ts(1,55): error TS2307: Cannot find module 'bugfinder-commitpath-quantifier-sonarqube' or its corresponding type declarations. npm ERR! src/sonarQubePredecessorsQuantifier/measurement/Visitors.ts(1,23): error TS2307: Cannot find module 'bugfinder-commitpath-quantifier-sonarqube' or its corresponding type declarations. npm ERR! src/sonarQubePredecessorsQuantifier/sonarQubePredecessorsQuantifier.ts(10,57): error TS2307: Cannot find module 'bugfinder-commitpath-quantifier-sonarqube' or its corresponding type declarations.

Expected Behavior

Npm install works fine.
Npm install of each package installs with cwd: package and the dependencies of the package`s package.json are locally used.

No response

Environment
  • OS: Windows 10
  • Node: 14.17.0
  • npm: 8.1.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the workspace layout from the issue on the stated Node and npm versions, starting with the root package.json workspaces and the package prepare/build scripts. Trace how npm install invokes each package's prepare script and verify completion by confirming that package-local dependencies resolve without the reported TypeScript TS2307 errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs, typescript
Domain
build-system, cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.