-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[JavaScript] - "node"
module resolution
#1760
Comments
Yoga took a dependence on ES modules for 3.0 to simplify the number of configurations, but that means type checker and bundler need to have some awareness of them. We removed the dependency on top-level await, because it was a bit too breaking, but the ecosystem is pretty increasingly depending on ES module semantics and resolution, so this is a place where projects really should try to put in the work to get a toolchain supporting them. We export the main entrypoint outside package.json exports, but reaching into |
Thanks for the detailed response. I agree that upgrading to modern module resolution is ideal, though it's not always possible in current projects. Currently we can't create libraries that work across both resolution strategies: // Works with 'node' resolution, fails with 'bundler'
import { Overflow } from 'yoga-layout/dist/src/load'
// Works with 'bundler' resolution, fails with 'node'
import { Overflow } from 'yoga-layout/load' Would something like this in the "exports": {
".": "./src/index.ts",
"./load": "./src/load.ts",
"./dist/src/load": "./dist/src/load.js",
"./dist/src/load.js": "./dist/src/load.js"
} |
I think I’d be okay with going the other way, of adding a “/load” entry point file that just lives at the root for those not able to use ES resolution or top level await. So long as it’s able to resolve to the right place, after the transformation we do when shipping the source (yarn prepack triggers this). |
Works for me. I'll make a PR at some point next week. |
@NickGerleman For further compatibility, what are your thoughts on switching the import extensions from |
We rewrite The packing step will also replace yoga/javascript/just.config.cjs Line 61 in 050ac8a
The declaration files do still have a The original source files pre-transform are also still there, without the rewriting, but they should never be directly imported. They are more useful just for source maps pointing to original source if debugging the released package. |
This approach doesn't work in TypeScript versions prior to 5.0 - you'll get
|
Oof, that's fun... It looks like we never tested this with a version before 5.0. Versions before 5.0 are out of support on DefinitelyTyped, but rewriting the imports in declarations is probably more correct, and pretty innocuous (the only case we use |
So it looks like declaration extensions don't get rewritten microsoft/TypeScript#59767 (comment) 🙃 For now, I see two paths:
|
Wouldn’t the first option break type-checking during development? If TypeScript team says that .d.ts files don’t get rewritten because they are allowed to import via .ts, and the supported (last two years) of TS allow this, it might be better not to fuss with too much. |
No, types are maintained. Try this branch - #1764 |
Report
Issues and Steps to Reproduce
When using Node module resolution, imports from subpaths like
yoga-layout/load
fail:This occurs because the package.json uses exports that require bundler module resolution
(https://github.com/facebook/yoga/blob/main/javascript/package.json#L15):
Many projects and libraries need to maintain compatibility with Node module resolution to support their users' existing codebases and build setups.
While direct application developers can potentially switch to "bundler" module resolution as a quick workaround, this becomes problematic for library authors building on top of yoga-layout. These library authors need to maintain the widest possible compatibility for their downstream users, making it difficult to require specific module resolution strategies.
Bundling yoga-layout as part of our library is not a viable solution as we want to leverage the existing npm ecosystem - allowing users to receive yoga-layout updates independently, maintain their own version management, and use standard module resolution patterns they're familiar with.
Expected Behavior
Imports from
yoga-layout/load
should resolve correctly when usingnode
module resolution, ensuring broader compatibility across different projects and build configurations.Actual Behavior
Get TypeScript error:
The text was updated successfully, but these errors were encountered: