问题
我在今天启动服务器时使用vite创建了一个React JS项目,在更新后遇到了这个错误
X [ERROR] [plugin vite:dep-pre-bundle] Detected inconsistent metadata for the path "node_modules/react/index.js" when it was imported here:
我使用的是vite 2.9.1版
问题的详细信息
vite v2.9.1 dev server running at:
> Local: http://localhost:3000/
> Network: use `--host` to expose
ready in 234ms.
X [ERROR] [plugin vite:dep-pre-bundle] Detected inconsistent metadata for the path "node_modules/react/index.js" when it was imported here:
node_modules/react/cjs/react-jsx-dev-runtime.development.js:16:20:
16 │ var React = require('react');
╵ ~~~~~~~
The original metadata for that path comes from when it was imported here:
dep:react:1:23:
1 │ export default require("./node_modules/react/index.js");
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The difference in metadata is displayed below:
{
- "pluginName": null,
+ "pluginName": "vite:dep-pre-bundle",
}
系统信息
System:
OS: macOS 12.2.1
CPU: (4) x64 Intel(R) Core(TM) i5-7600 CPU @ 3.50GHz
Memory: 426.07 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 17.9.0 - /usr/local/bin/node
Yarn: 1.22.17 - ~/.config/yarn/global/node_modules/.bin/yarn
npm: 8.5.5 - /usr/local/bin/npm
Browsers:
Chrome: 100.0.4896.75
Edge: 100.0.1185.39
Safari: 15.3
npmPackages:
@vitejs/plugin-vue: ^2.3.0 => 2.3.1
vite: 2.9.1 => 2.9.1
这个问题是关于"esbuild"的。
https://github.com/vitejs/vite/issues/7683
你可以修复它,只需运行
yarn update esbuild // or npm update esbuild