-
Notifications
You must be signed in to change notification settings - Fork 132
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
Add Node-specific export condition for ESM entrypoint that re-exports CJS #201
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, this seems fine.
@weswigham can you take a look at this one too? |
}, | ||
"import": { | ||
"node": "./modules/index.js", | ||
"default": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is relying on microsoft/TypeScript#50762 to resolve types for the node
import
case, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s going to use #200
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming the plan is to add another types
entry for the import
node
case, this seems OK. Though.... what currently resolves export maps without the node
condition (but with the import
condition) anyway? Might just be good to have an idea of what runtimes that branch is actually for.
I also want to know this. I (indirectly) asked @justinfagnani at #171 (comment). |
Bundler configurations targeting browsers could do that. For example, Rollup doesn't include It also doesn't even include |
Oh yeah, sure, but bundlers are all capable of running into CJS files too. I wanted to know who’s doing this and doesn’t support CJS modules at all. |
FWIW, this has caused a regression in Jest jestjs/jest#14173 From my understanding, when given FWIW, Jest follows Node: https://nodejs.org/api/packages.html#packagejson-and-file-extensions
|
This sounds like a bug in Jest. Perhaps you are only looking into the root |
It resolves to What might be wrong is applying node semantics to Note that |
Ah, sorry - I missed that this was about requests without the
It's kinda hard to tell for me on the spot - since that's usually bundlers' territory and they tend to do different interop things. @andrewbranch prepared a comprehensive table that showcases a lot of things (here) but I have a hard time unwrapping this quickly to find the positions related to your specific situation. What is easy to test is the node's behavior and this one just throws a
This seems quite reasonable to me as that would only alter this It's probably best to wait on Andrew's opinion though. |
On principle, I agree it’s sketchy at best to ship a Can Jest handle CJS format files at all? If so, why is it setting the |
Thinking about duplicating |
Yes, that's the default - ESM is opt in (since Node's
It's a browser-like environment ( |
tslib's package.json exports are now ambigous. a. All Files under the tslib's exports should ideally not have this ambiguity. I notice that with webpack's Are you planning to do anything about the exports' ambiguity in tslib? |
IIUC, the |
@Andarist Then I guess the exports of tslib are not ambigous but rather incorrect? |
To quote @andrewbranch:
If we assume that the node's behavior is the correct one here that guides everything else... then ye, I'd classify this as incorrect. Different tools implement things slightly differently though so at times it's super hard to determine how to solve things to satisfy everybody though. I think that |
// file.js
const path = require('node:path');
const enhancedResolve = require('enhanced-resolve');
const resolver = enhancedResolve.create({
// this is the important bit
conditionNames: ['browser', 'import'],
});
console.log(require('tslib/package.json').version);
const cwd = process.cwd();
resolver(cwd, 'tslib', (err, res) => {
if (err) {
console.error('got an error', err);
} else {
console.log(path.relative(cwd, res));
}
}); $ node file.js
2.5.2
node_modules/tslib/tslib.es6.js
FWIW, I agree with this. The |
I was hoping to get feedback on this
|
That should work fine, and no drawbacks as far as I know |
The irony of exporting |
Another stab at #171 / #143. Ensures non-Node module resolvers that use
import
do not see CommonJS, while still ensuring Node only ever sees one copy of the helpers.