yarn icon indicating copy to clipboard operation
yarn copied to clipboard

CLI switch "--scripts-prepend-node-path" doesn't work

Open jakedevine opened this issue 7 years ago • 7 comments

Do you want to request a feature or report a bug? Bug

What is the current behavior? Using the --scripts-prepend-node-path switch seems not to do anything.

$ /myNodePath/bin/node myYarnPath/bin/yarn.js run --scripts-prepend-node-path env

Running this outputs an "env" without myNodePath in the "PATH".

{
  "NODE": "/myNodePath/bin/node",
  ...
  "PATH": "/myProject/node_modules/.bin:/Users/jdevine/.config/yarn/link/node_modules/.bin:/myProject/node_modules/.bin:/myProject/node_modules/.bin:/Users/jdevine/.config/yarn/link/node_modules/.bin:/myProject/node_modules/.bin:/myNodePath/libexec/lib/node_modules/npm/bin/node-gyp-bin:/myNodePath/lib/node_modules/npm/bin/node-gyp-bin:/myNodePath/bin/node_modules/npm/bin/node-gyp-bin:/usr/local/sbin:/usr/local/bin:/Users/jdevine/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
  ...

We would expect that the node path (/myNodePath/bin) be the first thing in the PATH in the env. In fact, if I comment out the config check in yarn:

//    if (config.scriptsPrependNodePath) {
      pathParts.unshift(path.join(path.dirname(process.execPath)));
//    }

If I make that change, then see what I expect - the path includes /myNodePath/bin, and my install scripts, and "yarn run" scripts work as expected.

{
  "NODE": "/myNodePath/bin/node",
  ...
  "PATH": "/myNodePath/bin/:/myProject/node_modules/.bin:/Users/jdevine/.config/yarn/link/node_modules/.bin:/myProject/node_modules/.bin:/myProject/node_modules/.bin:/Users/jdevine/.config/yarn/link/node_modules/.bin:/myProject/node_modules/.bin:/myNodePath/libexec/lib/node_modules/npm/bin/node-gyp-bin:/myNodePath/lib/node_modules/npm/bin/node-gyp-bin:/myNodePath/bin/node_modules/npm/bin/node-gyp-bin:/usr/local/sbin:/usr/local/bin:/Users/jdevine/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
  ...

If the current behavior is a bug, please provide the steps to reproduce. This reproduces every time.

What is the expected behavior? As above. We expect that using --scripts-prepend-node-path should prepend the node path to the PATH in the environment when scripts are executed at install time and run time.

Please mention your node.js, yarn and operating system version. node v8.10.0 yarn v1.6.0

jakedevine avatar May 03 '18 00:05 jakedevine

Is --scripts-prepend-node-path actually a yarn flag? I can't seem to find any documentation or reference for it. Maybe this is a feature request to add a flag that npm has?

rally25rs avatar May 03 '18 13:05 rally25rs

Yeah - this probably comes from npm. I'm new to yarn, but it is in the code...

https://github.com/yarnpkg/yarn/blob/a35a4f97dd7e5f6f029b5e0f855bfd73ef338ca4/src/cli/index.js#L99-L103

jakedevine avatar May 03 '18 15:05 jakedevine

oops! yes it is. Text search failed me when I tried to find it in the code. My fault.

It's implemented too:

https://github.com/yarnpkg/yarn/blob/master/src/util/execute-lifecycle-script.js#L177-L179

rally25rs avatar May 03 '18 15:05 rally25rs

I would love to take this one 😊

antrancs avatar May 04 '18 20:05 antrancs

There appears to have been a regression.

See: https://github.com/yarnpkg/yarn/blob/a35a4f97dd7e5f6f029b5e0f855bfd73ef338ca4/src/util/execute-lifecycle-script.js#L177

As of 1.11.0 and later versions, that logic is not applied.

michaelsbradleyjr avatar Jan 15 '19 19:01 michaelsbradleyjr

is this just the default behavior of yarn?

ntindle avatar Aug 02 '21 23:08 ntindle

The flag existed prior to yarn 1.15, per the changelog it was removed as this is now the default behavior (as @ntindle said)

However, I still get an error and suggestion to use the flag occasionally: The node binary used for scripts is /tmp/yarn--1699538891283-0.12770085615992421/node but npm is using /usr/bin/node itself. Use the --scripts-prepend-node-path option to include the path for the node binary npm was executed with.

douglascayers avatar Nov 09 '23 14:11 douglascayers