fs in ./node_modules/bindings/bindings.js, ./node_modules/destroy/index.js and 6 others

时间:2022-06-18
本文章向大家介绍fs in ./node_modules/bindings/bindings.js, ./node_modules/destroy/index.js and 6 others,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

在启动mpvue项目时,报如下图所示的错误:

屏幕快照 2019-02-01 下午3.02.35.png

根据报错提示需要安装:

npm install --save child_process fs

但是安装完成后,再次运行:npm run dev 还是报同样的错误!

百度后,发现解决问题的方法:

  1. 找到build文件下的 webpack.base.conf.js
  2. 在如下图位置:

上图所示代码:

node: {
    // prevent webpack from injecting useless setImmediate polyfill because Vue
    // source contains it (although only uses it if it‘s native).
    setImmediate: false,
    // prevent webpack from injecting mocks to Node native modules
    // that does not make sense for the client
    dgram: "empty",
    fs: "empty",
    net: "empty",
    tls: "empty",
    child_process: "empty"
  }

完成后,再次运行:npm run dev 就可以了!