Skip to content
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

Typescript fails with ESM + Node16 (NodeNext) #6797

Open
3 tasks done
ferminc opened this issue Apr 25, 2024 · 1 comment
Open
3 tasks done

Typescript fails with ESM + Node16 (NodeNext) #6797

ferminc opened this issue Apr 25, 2024 · 1 comment
Labels

Comments

@ferminc
Copy link

ferminc commented Apr 25, 2024

Prerequisites

Describe the bug

When setting "type": "module" in package.json + "module": "node16" (or nodeNext), "moduleResolution": "node16" in tsconfig, typescript won't work correctly with React-Bootstrap, doing "import x from 'react-bootstrap/x'" will throw "JSX element type 'x' does not have any construct or call signatures."

Typescript will work correctly when using "import { x } from 'react-bootstrap'"

Additional info from https://arethetypeswrong.github.io/?p=react-bootstrap%402.10.2 :


Missing export =

The JavaScript appears to set both module.exports and module.exports.default for improved compatibility, but the types only reflect the latter (by using export default). This will cause TypeScript under the node16 module mode to think an extra .default property access is required, which will work at runtime but is not necessary. These types export = an object with a default property instead of using export default.

🤨
CJS default export

CommonJS module simulates a default export with exports.default and exports.__esModule, but does not also set module.exports for compatibility with Node. Node, and some bundlers under certain conditions, do not respect the __esModule marker, so accessing the intended default export will require a .default property access on the default import.

Expected behavior

TS should be able to recognize the export

To Reproduce

No response

Reproducible Example

https://stackblitz.com/edit/vitejs-vite-5mhtbn?file=src%2FApp.tsx

Screenshots

Untitled

What operating system(s) are you seeing the problem on?

No response

What browser(s) are you seeing the problem on?

No response

What version of React-Bootstrap are you using?

2.10.2

What version of Bootstrap are you using?

5.3.0

Additional context

No response

@ferminc ferminc added the bug label Apr 25, 2024
@ferminc
Copy link
Author

ferminc commented Apr 25, 2024

Replacing every "export default" with "export =" in all .d.ts files inside "node_modules\react-bootstrap\esm" has fixed the issue for me for now

image

@ferminc ferminc changed the title Typescript fails with ESM + Node16 Typescript fails with ESM + Node16 (NodeNext) Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant