laravel 找不到模块:错误:无法解析“fs”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40950176/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:51:56  来源:igfitidea点击:

Module not found: Error: Can't resolve 'fs'

laravelgulpwebpacklaravel-5.3laravel-elixir

提问by abu abu

I working on a Laravel 5.3 project. I am getting below errors when I am running gulpcommand in CMD.

我在 Laravel 5.3 项目上工作。gulp在 CMD 中运行命令时出现以下错误。

enter image description here

在此处输入图片说明

Could anyone say how can I get a error less result ?

谁能说我怎么能得到一个错误更少的结果?

gulpfile.js

gulpfile.js

var elixir = require('laravel-elixir');

require('laravel-elixir-vue');

elixir(function(mix) {
    mix.sass('app.scss');
});


elixir(function(mix) {
   mix.webpack('app.js');
}); 


elixir(function(mix) {
    mix.version(['css/app.css', 'js/app.js']);
});

package.json

包.json

{
  "private": true,
  "scripts": {
    "prod": "gulp --production",
    "dev": "gulp watch"
  },
  "devDependencies": {
    "babel-core": "^6.18.2",
    "babel-loader": "^6.2.7",
    "babel-plugin-add-module-exports": "^0.2.1",
    "bootstrap": "^4.0.0-alpha.3",
    "bootstrap-sass": "^3.3.7",
    "buble": "^0.14.2",
    "gulp": "^3.9.1",
    "jquery": "^3.1.0",
    "laravel-elixir": "^6.0.0-9",
    "laravel-elixir-browserify-official": "^0.1.3",
    "laravel-elixir-vue": "^0.1.4",
    "laravel-elixir-vue-2": "^0.2.0",
    "laravel-elixir-webpack-official": "^1.0.2",
    "lodash": "^4.14.0",
    "vue": "^1.0.26",
    "vue-resource": "^0.9.3"
  },
  "dependencies": {
    "admin-lte": "^2.3.7",
    "node-sass": "^3.13.0"
  }
}

回答by TimothePearce

If your using Laravel 5.5 or above, simply add:

如果您使用 Laravel 5.5 或更高版本,只需添加:

mix.webpackConfig({ node: { fs: 'empty' }})

to your webpack.mix.jsfile.

到您的webpack.mix.js文件。

回答by Antonio Carlos Ribeiro

Try adding

尝试添加

Elixir.webpack.mergeConfig({
  node: {
    fs: 'empty',
  }
});

To your gulpfile.js. Looks like this is a known webpack problem. Here's your file edited:

到你的gulpfile.js。看起来这是一个已知的 webpack 问题。这是您编辑的文件:

var elixir = require('laravel-elixir');

require('laravel-elixir-vue');

Elixir.webpack.mergeConfig({
  node: {
    fs: 'empty',
  }
});


elixir(function(mix) {
    mix.sass('app.scss');
});


elixir(function(mix) {
   mix.webpack('app.js');
}); 


elixir(function(mix) {
    mix.version(['css/app.css', 'js/app.js']);
});