-
-
Notifications
You must be signed in to change notification settings - Fork 387
Add './node' subpath export for node entry point #741
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' subpath export for node entry point #741
Conversation
Add `module-sync` in exports, exposing entry points to require/ESM loading.
I think the separation of Node.js vs the rest has caused us way too many problems. How about we always export That will probably fix all the other import issues too, since our package.json could go back to:
|
That will also mix the dependency tree, definitely a no go. I think in separation is actually working great, and that feature is a massive advantage of the ECMAScript module. Without that, I don't see the point we moved away from CommonJS. Yet there are workaround on the user side possible as well, such as raising the {
"compilerOptions": {
"target": "es2022",
"moduleResolution": "bundler",
"customConditions": ["node"]
}
}
Getting back to a more basic "exports": {
"node": {
"types": "./index.d.ts",
"default": "./index.js"
},
"default": {
"types": "./core.d.ts",
"default": "./core.js"
}
},
Yet I have nothing against the subpath exports, if that helps some users, it does not disturb anything else. The biggest issue we have now are |
The same dependencies are installed for all export types, so not really sure what you mean. |
For example |
The method would, yes, but we would simply make it throw when called and the |
To me it feels going from one extreme to the other. Again, I don't see why we should throw a good working mechanism overboard. Only in the TypeScript bundler the Node condition is not picked up, which probably relies in more in the nature of the bundler, or maybe even on how the bundler's project is setup. I see no reason to drastically change our architecture, but more then happy to add an extra sub-path export if that helps them to plugin the Node functionality. What is much more important, is to support require-esm, there is massive need for that solution. I propose to give this PR a try, and see how that works out. I have no problem with sustaining the |
I don't really see what's extreme about it. There is really nothing inherently tied to Node.js for this package other than the file access, which can easily be isolated to a single method. Regardless of the sub-export problems, having the package as platform agnostic as possible is a good goal. |
I totally agree with that!
The contradiction I see is objecting to my proposal of extending the current import condition with The second contradiction is moving away from a purist Node.js ESM specification. Your proposal replaces the clear-cut ESM conditions for accessing the Node API with a mechanism that relies on the success of lazy loading the Node.js API. The third contradiction is the rejection of workarounds. Exporting a sub-path is a very minor change that doesn’t impact anything else, yet it’s dismissed solely because it’s seen as a workaround. In contrast, replacing the Node ESM condition with lazy loading is a drastic workaround with potential side effects. |
Sub-exports is a Node.js invented thing and not part of ESM.
No, both are completely valid methods to achieve the same goal.
I may seem minor, but it too can have side-effects. What if a package depends on it, and then a consumer of that package wants to use that package in the browser. Then that package has locked into using the Node.js API since they forced the
This change too has potential side-effects. |
I don't really want to waste more time discussing this, so fine, we can do it your way. |
`./core` has been inherited at the days this package was CJS, where the default exports was Node.js. The core allowed to import the functionality, which did not depend on the Node API. With ES Module implementation, it is the other way around. The non-Node is now the default. Therefor it make more sense expose the Node specific functionality, for those cases where conditional exports cannot be used. Such as the ``"moduleResolution": "bundler"` in TypeScript projects.
acaa556
to
4ef2866
Compare
Add
./node
subpath export./core
has been inherited at the days this package was CJS, where the default exports was Node.js. The core allowed to import the functionality, which did not depend on the Node API. With ES Module implementation, it is the other way around. The non-Node is now the default. Therefor it make more sense expose the Node specific functionality, for those cases where conditional exports cannot be used. Such as the ``"moduleResolution": "bundler"` in TypeScript projects.I chose to use the
default
export in this case as generic fallback that always matches, as the subpath import is the user overruling the import in cases where the conditional imports have no, or not the desired effect.Fixes #652
Fixes #738