8000 Add CJS to exports map by nwalters512 · Pull Request #6919 · react-bootstrap/react-bootstrap · GitHub
[go: up one dir, main page]

Skip to content

Add CJS to exports map #6919

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nwalters512
Copy link
Contributor

It was called out in #6901 that the ESM build of this package is really only "faux" ESM; that is, import statements don't use fully-qualified paths with extensions, which is required for runtimes like Node. The addition of "exports" to package.json in #6901 poses a compatibility issue if this package continues shipping faux ESM: this package will be unusable in Node applications that are using native ESM. If one tries to import something like react-bootstrap/Card in such an application, one will see the following error:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/.../node_modules/react-bootstrap/lib/ThemeProvider' imported from /.../node_modules/react-bootstrap/lib/Card.js

A workaround would be to directly import the CJS files, e.g. react-bootstrap/cjs/Card.js, but trying to do that on current master fails with the following:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './cjs/Card.js' is not defined by "exports" in /.../node_modules/react-bootstrap/package.json imported from /.../index.js

This is expected, but leaves consumers of this package without any option to work around the faux ESM issue.

I'm opening this PR to give folks in this situation an escape hatch: they can explicitly use the CJS build with something like the following:

import Card from 'react-boostrap/cjs/Card'

If you plan on resolving the faux ESM issue before the release of "exports" in package.json, you can safely disregard this PR.

@kyletsang
Copy link
Member

Will try to address as much as I can for the next major, so won't merge this for now.

@reteps
Copy link
reteps commented Jun 26, 2025

Any progress on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0