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

[Feature] - Support for node --conditions flag in subpath imports #5171

Closed
1 of 2 tasks
owenallenaz opened this issue Jan 3, 2023 · 0 comments · Fixed by #5228
Closed
1 of 2 tasks

[Feature] - Support for node --conditions flag in subpath imports #5171

owenallenaz opened this issue Jan 3, 2023 · 0 comments · Fixed by #5228
Assignees
Labels
enhancement New feature or request

Comments

@owenallenaz
Copy link

owenallenaz commented Jan 3, 2023

  • I'd be willing to implement this feature (contributing guide)
  • This feature is important to have in this repository; a contrib plugin wouldn't do

Describe the user story

A package can contain subpath imports as declared here.

Then I should be able to require that content via: const something = require("#hax");. That syntax there works just fine, but not if you specify the node cli option --conditions. For example, I should be able to declare:

imports: {
   "#hax": {
     "development": "./src/hax.js",
     "default": "./src/hax_default.js"
   }
}

hax.js

exports.test = function() {
    console.log("called");
}

hax_default.js

exports.test = function() {
    console.log("hax_default called");
}

test.js

const { test } = require("#hax");

test();

Using the setup above if I execute:

: node test.js
hax_default called (CORRECT)
: node --conditions development test.js
called (CORRECT)
: yarn node test.js
hax_default called (CORRECT)
: yarn node --conditions development test.js
hax_default called (WRONG!)

This indicates that the yarn berry loader isn't properly utilizing the --conditions flag of Node.

Tested on:
node: v16.18.0
yarn: 3.2.4

This does not happen if I utilize nodeLinker: "node-modules". It works correctly in that situation.

@owenallenaz owenallenaz added the enhancement New feature or request label Jan 3, 2023
@merceyz merceyz self-assigned this Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants