vite2+vue3使用tsx報錯React is not defined、h is not defined


vite.jsx.tsx 文件提供開箱即用支持。

如果不是在 react 中使用 jsx,對於報錯:

React is not defined

需要在 vite.config.js 文件中添加如下配置:

export default {
  esbuild: {
    jsxFactory: 'h',
    jsxFragment: 'Fragment'
  }
}

此時重新啟動項目如有報錯:

h is not defined

需要在 .jsx.tsx 文件中手動引入 import { h } from 'vue';

或者使用vite的注入helper自動引入 h

export default {
  esbuild: {
    jsxInject: "import { h } from 'vue';"
  }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM