npm / npm/cli

[BUG] Path of 3rd cli tools have invalid location under workspace

Open
#4,103 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

// package.json
{
  "private": true,
  "workspaces": ["prj"]
}
// prj/package.json
{
  "name": "@my/prj",
  "version": "0.0.1",
  "scripts": {
    "postinstall": "babel src --our-dir dest"
  }, 
   "devDependencies": {
    "@babel/cli": "^7.14.5"
  }
}
npm install

It fails in windows cause node_modules\@my\prj\node_modules\.bin\babel.cmd reference %~dp0\..\..\..\node_modules\@babel\cli\bin\babel.js. I think cli generate path relative from prj\node_modules\.bin to node_modules\@babel\cli\bin\babel.js. Bug postinstall executing under node_modules/@my/prj, so it fails:

error C:\tmp\demo\node_modules\@my\prj: Command failed.
Exit code: 1
Command: babel src
Arguments:
Directory: C:\temp\demo\node_modules\@my\prj
Output:
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module 'C:\temp\demo\node_modules\@my\node_modules\@babel\cli\bin\babel.js'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
Expected Behavior

postinstall run after this workspace copy from prj to node_modules\@my\prj. So it should reference path relative from node_modules\@my\prj\node_modules\.bin\babel.cmd to node_modules\@babel\cli\bin\babel.js. So I can not use any "/" structure for naming package under workspaces right now.

Environment
  • npm: 8
  • Node: 16.13
  • OS: win10

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 Windows workspace setup using the root package.json and prj/package.json, then inspect node_modules/@my/prj/node_modules/.bin/babel.cmd and the @babel/cli path it references. Start with npm install and the postinstall script; done means the workspace copy can run Babel without a MODULE_NOT_FOUND error and resolves the expected node_modules location.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
build-system, cli
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.