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

[bug?]import {jsx} from 'react/jsx-runtime' would throw error in package with type: module #2446

Closed
indooorsman opened this issue Aug 8, 2022 · 2 comments

Comments

@indooorsman
Copy link

e.g.:
I bundle a lib package with latest esbuild(format: esm, target: chrome100 & "type":"module" in package.json), which export a react component, by default the output would be something like:

import { jsx } from 'react/jsx-runtime';
....

then if some project used my lib but bundle with webpack, the error would happen:
image

in my opinion, if my package set type to module explicitly, esbuild should add .js to the import path:

import { jsx } from 'react/jsx-runtime.js';
....
@evanw
Copy link
Owner

evanw commented Aug 8, 2022

This is documented here: https://esbuild.github.io/api/#jsx-import-source

The /jsx-runtime and /jsx-dev-runtime subpaths are hard-coded by design and cannot be changed.

This is deliberate behavior.

in my opinion, if my package set type to module explicitly, esbuild should add .js to the import path:

import { jsx } from 'react/jsx-runtime.js';

They tried doing what you suggested, and then they reverted it because it was a bad idea: babel/babel#12210. Closing this issue as esbuild is working as intended. Your bug report is a problem with React, not with esbuild, and this problem was fixed in React 18: facebook/react#20235 (comment).

@evanw evanw closed this as not planned Won't fix, can't repro, duplicate, stale Aug 8, 2022
@indooorsman
Copy link
Author

This is documented here: https://esbuild.github.io/api/#jsx-import-source

The /jsx-runtime and /jsx-dev-runtime subpaths are hard-coded by design and cannot be changed.

This is deliberate behavior.

in my opinion, if my package set type to module explicitly, esbuild should add .js to the import path:

import { jsx } from 'react/jsx-runtime.js';

They tried doing what you suggested, and then they reverted it because it was a bad idea: babel/babel#12210. Closing this issue as esbuild is working as intended. Your bug report is a problem with React, not with esbuild, and this problem was fixed in React 18: facebook/react#20235 (comment).

Got it, thanks

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

No branches or pull requests

2 participants