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

Automatically inject the JSX runtime #558

Closed
mquandalle opened this issue Feb 1, 2022 · 3 comments
Closed

Automatically inject the JSX runtime #558

mquandalle opened this issue Feb 1, 2022 · 3 comments

Comments

@mquandalle
Copy link

I recently migrated a React package to tsup and encountered the issue React is not defined

The solution is to specify a JSX runtime which is possible since the introduction of the --inject option in #390. But it still require creating a react-shim.js file.

Inferring the correct runtime from tsconfig would greatly improve the developer experience.

@gyfchong
Copy link

Also ran into this problem. It's very confusing for the bundler to not recognise the jsx runtime in tsconfig.

@lunacrafts
Copy link

This configuration seems to work for me (at this moment at last). Would be great to put it somewhere in docs. It was very time consuming to make it work.

// tsup.config.js
import { defineConfig } from 'tsup';
export default defineConfig((options) => {
  return {
    entry: ["./src/index.ts"],
    format: ["esm", "cjs"],
    external: ['react', 'react-dom'],
    dts: false,
    sourcemap: false,
    splitting: true,
    metafile: true,
    inject: ['./react-shim.js'],
    onSuccess: "tsc --emitDeclarationOnly --declaration",
    minify: !options.watch
  }
});
// package.json
{
  "name": "library-name",
  "version": "0.0.0",
  "description": "",
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "exports": {
    ".": {
      "require": "./dist/index.js",
      "import": "./dist/index.mjs",
      "types": "./dist/index.d.ts"
    }
  },
  "files": [
    "dist/**"
  ],
  "scripts": {
    "dev": "tsup --watch",
    "build": "tsup"
  },
}

@jlarmstrongiv
Copy link

jlarmstrongiv commented Nov 27, 2022

Was this fixed in #715 (comment) ?

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

4 participants