开发者问题收集

Vite - esbuild.x 不与 vite 进行比较

2022-07-20
134

问题

我使用 vite 创建了一个 React JS 项目,今天启动服务器时,更新后遇到了这个错误

X [ERROR] [plugin vite:dep-pre-bundle] 在此处导入时检测到路径“node_modules/react/index.js”的元数据不一致:

我使用的是 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
1个回答

此问题与 'esbuild' 有关。

https://github.com/vitejs/vite/issues/7683

您可以修复它,只需运行

yarn update esbuild // or npm update esbuild
JoeH
2022-10-31