Webpack错误-configuration.node具有未知属性'fs' [英] Webpack Error - configuration.node has an unknown property 'fs'

查看:1571
本文介绍了Webpack错误-configuration.node具有未知属性'fs'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用最新版本的Webpack(5.1.0)时遇到错误.似乎配置抛出错误,因为验证架构的限制太多.这是我的webpack配置文件的摘要,以及我看到的错误消息.

I have encountered an error when using the latest version of Webpack (5.1.0). It looks like the configuration is throwing an error because the validation schema is too restrictive. Here is my webpack configuration file in a gist, and the error message I am seeing.

Webpack.config.js

https://gist.github.com/adarshbhat/3ec5950b66b78102da0cf46e51a3d633

错误

[webpack-cli] 
Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration.node should be one of these:
   false | object { __dirname?, __filename?, global? }
   -> Include polyfills or mocks for various node stuff.
   Details:
    * configuration.node has an unknown property 'module'. These properties are valid:
      object { __dirname?, __filename?, global? }
      -> Options object for node compatibility features.
    * configuration.node has an unknown property 'net'. These properties are valid:
      object { __dirname?, __filename?, global? }
      -> Options object for node compatibility features.
    * configuration.node has an unknown property 'fs'. These properties are valid:
      object { __dirname?, __filename?, global? }
      -> Options object for node compatibility features.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! jstest@1.0.0 start: `webpack serve`
npm ERR! Exit status 2

我正在尝试使用在Node.js环境以及浏览器中都可以使用的解析器生成器库(antlr4).似乎库代码需要像fs这样的全局对象,如果为空,则假定它在浏览器环境中.根据 Antlr4文档 Webpack ,这是受支持的配置文件.但这是行不通的.请帮忙.

I am attempting to use a parser generator library (antlr4) that works both in a Node.js environment, as well as in browsers. It looks like the library code is requiring global objects like fs, and if it is empty, assumes that it is in a browser environment. According to the documentation of Antlr4 and that of Webpack , this is a supported configuration file. But it is not working. Please help.

版本

  • webpack:5.1.0
  • webpack-cli:4.0.0
  • webpack-dev-middleware:3.7.2
  • webpack-dev-server:3.11.0

更新(2020年10月29日)

Antlr JavaScript文档现已使用Webpack 5的新配置进行了更新

Antlr JavaScript documentation has now been updated with the new configuration for Webpack 5

推荐答案

在Webpack团队的一些帮助下,我设法使它起作用.不再支持使用antlr4文档建议的以下webpack配置.

I managed to get this to work with some help from the Webpack team. Using the following webpack configuration as recommended by the antlr4 documentation is no longer supported.

不起作用

{
  node: {
    fs: 'empty',
    module: 'empty',
    net: 'empty'
  }
}

工作配置

resolve: {
  fallback: {
    fs: false
  }
}

有了这个,我得以使我的JavaScript解析器正常工作.

With this, I was able to get my JavaScript parser working.

请注意,正在持续努力更新antlr4以生成基于ES6的代码.将来可能不需要此配置.

Please note that there is an ongoing effort to update antlr4 to generate ES6 based code. This configuration may not be necessary in the future.

这篇关于Webpack错误-configuration.node具有未知属性'fs'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆