Point main at the CJS build so named imports resolve under Node - #56
Open
nandastone wants to merge 1 commit into
Open
Point main at the CJS build so named imports resolve under Node#56nandastone wants to merge 1 commit into
nandastone wants to merge 1 commit into
Conversation
The UMD bundle assigns its export inside the factory, where Node's CJS
lexer cannot see it, so `import { Collapse }` resolves to undefined for
anything using Node resolution. dist/react-collapse.cjs already ships and
ends with a plain `exports.Collapse`, which is detectable.
Restores the exports map removed in 74a7131, against the current
filenames, with a ./dist/* passthrough so the deep paths the README
documents keep working.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Importing the library by name gives you
undefinedwherever Node's resolver does the work:React then reports
Element type is invalid ... got: undefined, which names neither the import nor this package.Bundlers are fine: they read
moduleand get the ESM build. Node readsmain, which points at the UMD bundle, and that bundle ends by assigning onto the factory's namespace argument,n.Collapse = P.cjs-module-lexeronly sees statically analysable assignments, so Node concludes the module has no named exports.dist/react-collapse.cjsalready ships beside it and endsexports.Collapse = B, which the lexer does see.mainhas never pointed there.The
exportsmap is the part worth your attention, since you removed one in 74a7131 and I'd rather not undo that. Reading the commit, the map looks like it was in the way: the same change addedrequire('@kunukn/react-collapse/dist/react-collapse.cjs')to the CommonJS playground, and a map blocks any subpath it does not list, so that require would have thrownERR_PACKAGE_PATH_NOT_EXPORTED. Dropping the map is what opened the deep-link route you gave the reporter in #51../dist/*keeps that route open by passing every path through. I checked the playground's deep require, the CSS import and the documented types path against an installed 3.0.15 with this patched in, along with the bare named import andrequire('@kunukn/react-collapse').The UMD build is untouched and still shipped, so the CDN usage in
_playground_global-jsis unaffected.