迁移Vite项目到4.x后,为什么插件报错说配置参数无效?

开发者恒菽 阅读 61

最近在把项目从Vite2迁移到4.x版本,按照迁移指南升级了依赖,但运行时提示@vitejs/plugin-react插件的配置参数jsxImportSource无效。明明迁移文档里说这个参数还存在啊,我检查了vite.config.js里插件的导入方式也没问题。试过删除node_modules和lock文件重装,还是同样的报错:

[vite] Invalid configuration for plugin @vitejs/plugin-react: "jsxImportSource" is not expected

配置文件里这部分是这样写的:

import react from '@vitejs/plugin-react'

export default defineConfig({
  plugins: [
    react({
      jsxImportSource: 'some/path' // 这里报错
    })
  ]
})

难道新版本移除了这个参数?但文档里没提到…

我来解答 赞 4 收藏
二维码
手机扫码查看
1 条解答
Top丶永景
应该是你用的 @vitejs/plugin-react 版本太新了,jsxImportSource 在新版里被移除了。React 插件现在默认用自动模式,直接删掉这个配置就行。

把你的配置改成这样:

import react from '@vitejs/plugin-react'

export default defineConfig({
plugins: [
react()
]
})


如果真要用自定义 jsx 导入,得装 babel-preset-react-jsx 并配 babel,但大多数项目根本不需要。
点赞 4
2026-02-09 02:03