Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jakedevine opened this issue May 3, 2018 · 7 comments
Open

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

jakedevine opened this issue May 3, 2018 · 7 comments

Comments

@jakedevine
Copy link

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

@ghost ghost assigned torifat May 3, 2018
@ghost ghost added the triaged label May 3, 2018
@rally25rs
Copy link
Contributor

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?

@jakedevine
Copy link
Author

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

yarn/src/cli/index.js

Lines 99 to 103 in a35a4f9

commander.option(
'--scripts-prepend-node-path [bool]',
'prepend the node executable dir to the PATH in scripts',
boolify,
);

@rally25rs
Copy link
Contributor

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

@antrancs
Copy link
Contributor

antrancs commented May 4, 2018

I would love to take this one 😊

@michaelsbradleyjr
Copy link

There appears to have been a regression.

See:

if (config.scriptsPrependNodePath) {

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

@ntindle
Copy link

ntindle commented Aug 2, 2021

is this just the default behavior of yarn?

@douglascayers
Copy link

douglascayers commented Nov 9, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants