美文网首页
vite安装vue项目报错(Error: esbuild: Fa

vite安装vue项目报错(Error: esbuild: Fa

作者: starsion | 来源:发表于2021-03-19 10:58 被阅读0次

最近尝试使用vite,初始化vue项目之后,运行 npm run dev 报错,问题分析以及解决方案记录一下。

报错内容如下:

报错内容

throw new Error(`esbuild: Failed to install correctly ^ Error: esbuild: Failed to install correctly   Make sure you don't have "ignore-scripts" set to true. You can check this with "npm config get ignore-scripts". If that returns true you can reset it back to false using "npm config set ignore-scripts false" and then reinstall esbuild.   If you're using npm v7, make sure your package-lock.json file contains either "lockfileVersion": 1 or the code "hasInstallScript": true. If it doesn't have either of those, then it is likely the case that a known bug in npm v7 has corrupted your package-lock.json file. Regenerating your package-lock.json file should fix this issue.   ...  at Module._compile (internal/modules/cjs/loader.js:1015:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10) at Module.load (internal/modules/cjs/loader.js:879:32) at Function.Module._load (internal/modules/cjs/loader.js:724:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12) at internal/main/run_main_module.js:17:47 ... error when starting dev server: Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed  at doWrite (_stream_writable.js:399:19) at writeOrBuffer (_stream_writable.js:387:5) ... npm ERR! command failed npm ERR! command sh -c vite ...

解读报错

  1. 首先确认是esbuild的报错,安装失败。

  2. 报错信息其实已经很清楚了

  3. 针对 npm 版本v7以下

    1. 首先确认 ignore-scripts 是否被设置成 true
    2. 运行 npm config get ignore-scripts ,如果是 false 则是正确的,否则需要通过运行 npm config set ignore-scripts falseignore-scripts设置为 false
    3. 通过设置之后,再次运行调试应该是ok的了。
  4. npm 版本v7以上的

    1. 还需要确认一下 package-lock.json 文件的 lockfileVersion 字段为 1 ,或者 hasInstallScript 设置为 true 了。如果两者都没有被正确设置,则就是一个已知的BUG。解决办法参看后文

npm > v7

  1. 通过github查阅vite仓库的相关issue【https://github.com/vitejs/vite/issues/1580】,尤大也很明确的指出这个是esbuild的BUG。

    image.png
  2. 问题的解决办法在【https://github.com/evanw/esbuild/issues/462#issuecomment-771328459】。

    image.png
  3. 手动运行 node node_modules/esbuild/install.js 来解决esbuild安装问题。

    image.png image.png
  4. 安装完成之后,再次运行 npm run dev 即可。

相关文章

网友评论

      本文标题:vite安装vue项目报错(Error: esbuild: Fa

      本文链接:https://www.haomeiwen.com/subject/rfrvcltx.html