Skip to content

npm shim is not used when running the npm command from a script #1935

Description

@Adrian-Baran-GY

Describe the bug

When running npm command from a script by using childProcess.execSync ~/.vite-plus/js_runtime/node/22.22.0/bin/npm is used instead of ~/.vite-plus/bin/npm, becuse ~/.vite-plus/js_runtime/node/22.22.0/bin is added before /home/ch4cha/.vite-plus/bin in the PATH. Is this expected behaviour? This is confusing as the output from npm --version command and childProcess.execSync("which npm", { cwd: projectDir, encoding: "utf-8", stdio: "pipe" }) differs.

Reproduction

Steps to reproduce

Given following package.json:

{
  "name": "test",
  "version": "1.0.0",
  "type": "module",
  "devEngines": {
    "packageManager": {
      "name": "npm",
      "version": "11.17.0",
      "onFail": "download"
    },
    "runtime": {
      "name": "node",
      "version": "22.22.0",
      "onFail": "download"
    }
  }
}

we have:

npm --version
# 11.17.0
which npm
# ~/.vite-plus/bin/npm

which is expected.

Given index.js:

import childProcess from "node:child_process";
import path from "node:path";

const projectDir = path.resolve(import.meta.dirname, ".");

try {
  const output = childProcess.execSync(`which npm`, {
    cwd: projectDir,
    encoding: "utf-8",
    stdio: "pipe",
  });
  console.log(output);
} catch (error) {
  console.error(String(error));
}

try {
  const output = childProcess.execSync(`npm --version`, {
    cwd: projectDir,
    encoding: "utf-8",
    stdio: "pipe",
  });
  console.log(output);
} catch (error) {
  console.error(String(error));
}

node index.js output is:

~/.vite-plus/js_runtime/node/22.22.0/bin/npm

11.14.1

npm version reported from the script is 11.14.1 instead of 11.17.0. This is because ~/.vite-plus/js_runtime/node/22.22.0/bin/npm is used instead of ~/.vite-plus/bin/npm. Is this expected? I would assume running commands via the script would use the same env as regular commands in the same directory.

System Info

VITE+ - The Unified Toolchain for the Web

Environment:
  Version       22.22.0
  Source        devEngines.runtime
  Source Path   ~/ps/test/package.json
  Project Root  ~/ps/test

Tool Paths:
  node  ~/.vite-plus/js_runtime/node/22.22.0/bin/node
  npm   ~/.vite-plus/js_runtime/node/22.22.0/bin/npm
  npx   ~/.vite-plus/js_runtime/node/22.22.0/bin/npx

Package Manager:
  Name          npm
  Version       11.17.0
  Source        devEngines.packageManager
  Source Path   ~/ps/test/package.json
  Project Root  ~/ps/test
  Bin Path      ~/.vite-plus/package_manager/npm/11.17.0/npm/bin/npm



VITE+ - The Unified Toolchain for the Web

vp v0.2.1

Local vite-plus:
  vite-plus  Not found

Tools:
  vite             Not found
  rolldown         Not found
  vitest           Not found
  oxfmt            Not found
  oxlint           Not found
  oxlint-tsgolint  Not found
  tsdown           Not found

Environment:
  Package manager  npm v11.17.0
  Node.js          v22.22.0 (devEngines.runtime)

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Priority

None yet

Effort

None yet

Target date

None yet

Start date

None yet

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions