vue3 jsx produces "React is not defined"
See original GitHub issuei am trying to implement storybook with antdesignvue i get the error “ReferenceError: React is not defined” when i tried to import a tsx file which returns jsx in button.stories.js file (screenshot is attached)
my settings are
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import Components from "unplugin-vue-components/vite";
import vueJsx from "@vitejs/plugin-vue-jsx";
// https://vitejs.dev/config/
export default defineConfig({
esbuild: {
jsxFactory: 'h',
jsxFragment: 'Fragment'
},
plugins: [
vue(),
vueJsx(),
Components({
dirs: ["./components"],
}),
],
});
tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": "./",
"paths": {
"ant-design-vue": ["components/index.ts"],
"ant-design-vue/es/*": ["components/*"],
"@components/*": ["./components/*"],
"@assets/*": ["./assets/*"],
},
"lib": [
"esnext",
"dom"
],
"strictNullChecks": false,
"moduleResolution": "node",
"esModuleInterop": true,
"experimentalDecorators": true,
"jsx": "preserve",
"noUnusedParameters": true,
"noUnusedLocals": true,
"noImplicitAny": false,
"skipLibCheck": true,
"importsNotUsedAsValues": "preserve",
"target": "es5",
"useDefineForClassFields": true,
"module": "esnext",
"strict": false,
"sourceMap": true,
"resolveJsonModule": true,
},
"exclude": ["node_modules", "lib", "es", "dist", "v2-doc", "scripts", "**/__tests__/**/*"],
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "es5",
"types": ["node", "vite/client"],
"include": [
"components/**/*.ts",
"components/**/*.d.ts",
"components/**/*.tsx",
"components/**/*.vue"
]
}
Button.stories.js
import Button from "../components/button/button";
export default {
title: "Button",
components: { Button },
};
const Template = (args) => ({
props: Object.keys(args),
components: { Button },
setup() {
return { args };
},
template: `
<Button v-bind="args" />
`,
});
export const Hello = Template.bind({});
Hello.args = {};
error screenshot is
every kind of help is much appreciated
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
`ReferenceError: React is not defined` in vue3 jsx files
stories. js, I got "ReferenceError: React is not defined" you can see error here but react is not the part of this project...
Read more >Render Functions & JSX | Vue.js
Although first introduced by React, JSX actually has no defined runtime semantics and can be compiled into various different outputs.
Read more >Using JSX with Vue - LogRocket Blog
This post will look at render functions and how they work along with JSX and why you might want to use it in...
Read more >Introducing JSX - React
JSX produces React “elements”. We will explore rendering them to the DOM in the next section. Below, you can find the basics of...
Read more >Features | Vite
The pre-bundling step is performed with esbuild and makes Vite's cold start ... If not using JSX with React or Vue, custom jsxFactory...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You are Genius!
Works perfect with:
.storybook/main.js
Tks @IanVS !!!
It looks like you are missing https://github.com/vitejs/vite/tree/master/packages/plugin-vue-jsx from the vite config. Adding vite plugins is a little bit tricky right now, but it can be done in
viteFinal
. Here’s an example of someone changing the plugins: https://github.com/storybookjs/builder-vite/issues/286#issue-1176508222. I think all you’ll need to do is push the one you want onto the end of the existingconfig.plugins
.