Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

This JSX tag requires 'React' to be in scope, but it could not be found.ts(2874)#498

Unanswered
dbzx10299 asked this question inQ&A
Discussion options

Below I have listed the file structure I have in my project as well as the Vite config file, if I create a component in the/src dir with a.tsx extension, the code does not have any red squiggly lines, but if I put the same code in the/lib dir, I get a red line that states:This JSX tag requires 'React' to be in scope, but it could not be found.ts(2874).

index.tsx

exportdefaultfunctionGrid(){return(<div>I am a grid</div>//   ^^^^  This JSX tag requires 'React' to be in scope, but it could not be found.ts(2874)// This error only happens if this component is in the /lib folder, but it does not occur in the /src folder)}
.└──lib/├──components/└──Button/└──index.tsx└──main.ts

vite.config.ts

import{defineConfig}from'vite'importvuefrom'@vitejs/plugin-vue'import{libInjectCss}from'vite-plugin-lib-inject-css'import{resolve}from'path'import{globSync}from'glob'importpathfrom'node:path';import{fileURLToPath}from'node:url';importdtsfrom'vite-plugin-dts'importvueJsxfrom'@vitejs/plugin-vue-jsx'// https://vite.dev/config/exportdefaultdefineConfig({plugins:[vue(),vueJsx(),libInjectCss(),dts({tsconfigPath:resolve(__dirname,"tsconfig.lib.json")})],esbuild:{jsxFactory:'h',jsxFragment:'Fragment',},build:{copyPublicDir:false,lib:{entry:resolve(__dirname,'lib/main.ts'),formats:['es']},rollupOptions:{external:['vue'],input:Object.fromEntries(globSync('lib/**/*.{ts,tsx}',{ignore:['lib/**/*.d.ts']}).map(file=>[path.relative('lib',file.slice(0,file.length-path.extname(file).length)),fileURLToPath(newURL(file,import.meta.url))])),output:{assetFileNames:'assets/[name][extname]',entryFileNames:'[name].js'}}}})
You must be logged in to vote

Replies: 0 comments

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
1 participant
@dbzx10299

[8]ページ先頭

©2009-2025 Movatter.jp