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

Automatic JSX Runtime not respected in node_modules #2513

Closed
chowey opened this issue Sep 1, 2022 · 2 comments
Closed

Automatic JSX Runtime not respected in node_modules #2513

chowey opened this issue Sep 1, 2022 · 2 comments

Comments

@chowey
Copy link

chowey commented Sep 1, 2022

I am trying to use Emotion with esbuild. In my main module, this works fine in my tsconfig.json:

{
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "@emotion/react"
  }
}

If I have the same thing in my node_modules folder, i.e. I use an un-transpiled TypeScript library directly in node_modules, this is no longer respected and the jsxImportSource seems to be ignored.

This is true even if I specify it directly in esbuild's build config. In other words, node_modules does not seem to support the automatic JSX runtime.

@evanw
Copy link
Owner

evanw commented Sep 1, 2022

If I have the same thing in my node_modules folder, i.e. I use an un-transpiled TypeScript library directly in node_modules, this is no longer respected and the jsxImportSource seems to be ignored.

This is happening because people requested that tsconfig.json be ignored by esbuild in node_modules: #1355. I think the idea is that people often accidentally publish their tsconfig.json files by forgetting to add them to .npmignore? From what I understand, publishing raw TypeScript files to npm is far less common than publishing transpiled JavaScript files along with type definitions, so this seems somewhat unusual.

This is true even if I specify it directly in esbuild's build config. In other words, node_modules does not seem to support the automatic JSX runtime.

I can't reproduce this. Here's what I tried:

$ mkdir -p node_modules/pkg
$ echo 'import "pkg"' > index.js
$ echo 'x = <y/>' > node_modules/pkg/index.jsx
$ esbuild --bundle --jsx=automatic index.js 
✘ [ERROR] Could not resolve "react/jsx-runtime"

    node_modules/pkg/index.jsx:1:4:
      1 │ x = <y/>
        ╵     ^

  You can mark the path "react/jsx-runtime" as external to exclude it from the bundle, which will
  remove this error.

This appears to support the automatic JSX runtime in node_modules.

@chowey
Copy link
Author

chowey commented Sep 2, 2022

This is happening because people requested that tsconfig.json be ignored by esbuild in node_modules: #1355. I think the idea is that people often accidentally publish their tsconfig.json files by forgetting to add them to .npmignore? From what I understand, publishing raw TypeScript files to npm is far less common than publishing transpiled JavaScript files along with type definitions, so this seems somewhat unusual.

That's too bad for me. I've found it simple and convenient (for internal modules) to directly reference them via git in my package.json file (no publish step):

{
  "dependencies": {
    "my-internal-module": "git+https://example.com/my/module#semver:^0.1.2",
  }
}

Obviously I'm in the minority here.

This appears to support the automatic JSX runtime in node_modules.

I'm seeing the same thing now. The esbuild Build config does work. This must have been a mis-observation on my part.

Certainly the settings in my main module's tsconfig.json don't seem to affect node_modules but I guess that is to be expected.

@chowey chowey closed this as completed Sep 2, 2022
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