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

Change in NODE_OPTIONS parsing behavior in Node 11 #26521

Closed
rwjblue opened this issue Mar 8, 2019 · 13 comments
Closed

Change in NODE_OPTIONS parsing behavior in Node 11 #26521

rwjblue opened this issue Mar 8, 2019 · 13 comments
Labels
cli Issues and PRs related to the Node.js command line interface. confirmed-bug Issues with confirmed bugs.

Comments

@rwjblue
Copy link

rwjblue commented Mar 8, 2019

  • Version: v11.9.0
  • Platform: Darwin
  • Subsystem:

If NODE_OPTIONS starts with a leading space the --require option does not function (possibly other flags but I've only tested --require).

Specifically:

NODE_OPTIONS="--require ./some-file.js" node ./other-file.js

^ will properly require ./some-file.js prior to executing ./other-file.js

Whereas:

NODE_OPTIONS=" --require ./some-file.js" node ./other-file.js

^^ will not require ./some-file.js at all

Steps to reproduce:

mkdir test-node-options
cd test-node-options
echo "console.log('first!')" > first.js
echo "console.log('second!')" > second.js

Then compare the output of these two commands:

# "broken"
NODE_OPTIONS=" --require ./first.js" node ./second.js

# "working"
NODE_OPTIONS="--require ./first.js" node ./second.js

I stumbled across this while attempting to use Yarn's PnP system on Node 11 (see yarnpkg/yarn#7092 for the original report there). Yarn 1.13.0 adds --require ${PATH_TO_PNP_FILE} to NODE_OPTIONS which causes this issue.

/cc @arcanis @Turbo87 @stefanpenner

@arcanis
Copy link
Contributor

arcanis commented Mar 8, 2019

Wow 😮 The most obvious suspect would be 8ec3c35

Probably a good time to put #24065 back on the table as well

@addaleax
Copy link
Member

addaleax commented Mar 8, 2019

@arcanis Do you want to continue work on your PR and fix this along with it? Otherwise we can do a new PR for this specific problem?

@addaleax addaleax added confirmed-bug Issues with confirmed bugs. cli Issues and PRs related to the Node.js command line interface. labels Mar 8, 2019
@arcanis
Copy link
Contributor

arcanis commented Mar 8, 2019

I'll give it a look this evening (I might have to revert part of 8ec3c35 since it wouldn't make sense to use the same SplitString anymore?) - if no progress by the end of the week feel free to fix it separately 🙂

@addaleax
Copy link
Member

addaleax commented Mar 8, 2019

@arcanis I think both consumers of SplitString() would like to skip empty items (which I assume is the issue here), so I think it’s okay to modify the common code. But yeah, reverting it should also be fine.

@stefanpenner
Copy link

@rwjblue thanks for debugging this one!

@himself65
Copy link
Member

Can we make SplitString() to trim white spaces?

@himself65
Copy link
Member

maybe we should ignore white spaces like this on SplitString()

    if (item.empty()) continue;

@arcanis
Copy link
Contributor

arcanis commented Mar 9, 2019

I've rebased, updated, and fixed this issue in #24065

@himself65
Copy link
Member

himself65 commented Mar 13, 2019

fixed on 17ab2ed

@stefanpenner
Copy link

@himself65 / @arcanis is the plan to ship this as part of an upcoming node@11.x.y release?

@himself65
Copy link
Member

@himself65 / @arcanis is the plan to ship this as part of an upcoming node@11.x.y release?

i don’t know :(

you can ask the Node Team Members about it.

@stefanpenner
Copy link

cc @addaleax ^

@lpinca
Copy link
Member

lpinca commented Mar 23, 2019

@stefanpenner it seems this shipped with Node.js 11.12.0. I'm going to close this. Please comment back if needed.

@lpinca lpinca closed this as completed Mar 23, 2019
stefanpenner added a commit to stefanpenner/resolve-package-path that referenced this issue Mar 23, 2019
When a script is invoked by yarn, it provides the appropriate -r via NODE_OPTIONS. This makes all node scripts invoke via yarn automatically pnp aware. 

Unfortunately NODE_OPTIONS was partially broken in node 11, preventing this from working.
Luckily node 11.12 fixed this issue.

Relevant issue: nodejs/node#26521
stefanpenner added a commit to stefanpenner/resolve-package-path that referenced this issue Dec 6, 2019
When a script is invoked by yarn, it provides the appropriate -r via NODE_OPTIONS. This makes all node scripts invoke via yarn automatically pnp aware. 

Unfortunately NODE_OPTIONS was partially broken in node 11, preventing this from working.
Luckily node 11.12 fixed this issue.

Relevant issue: nodejs/node#26521
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Issues and PRs related to the Node.js command line interface. confirmed-bug Issues with confirmed bugs.
Projects
None yet
Development

No branches or pull requests

6 participants