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

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

问题描述

我在使用最新版本的 Webpack (5.1.0) 时遇到错误.看起来配置正在抛出错误,因为验证架构过于严格.这是我的 webpack 配置文件的要点,以及我看到的错误消息.

Webpack.config.js

https://gist.github.com/adarshbhat/3ec5950b66b78102da50cf>错误

[webpack-cli]无效的配置对象.Webpack 已使用与 API 架构不匹配的配置对象进行初始化.- configuration.node 应该是以下之一:假|对象 { __dirname?, __filename?, global?}->包括用于各种节点内容的 polyfill 或模拟.细节:* configuration.node 有一个未知的属性模块".这些属性有效:对象 { __dirname?, __filename?, global?}->节点兼容性功能的选项对象.* configuration.node 有一个未知的属性net".这些属性有效:对象 { __dirname?, __filename?, global?}->节点兼容性功能的选项对象.* configuration.node 有一个未知的属性fs".这些属性有效:对象 { __dirname?, __filename?, global?}->节点兼容性功能的选项对象.npm 错误!代码生命周期npm 错误!错误 2npm 错误!jstest@1.0.0 开始:`webpack serve`npm 错误!退出状态 2

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

版本

  • 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 的新配置

解决方案

在 Webpack 团队的一些帮助下,我设法让它发挥了作用.不再支持使用 antlr4 文档推荐的以下 webpack 配置.

不起作用

{节点:{fs: '空',模块:'空',净:'空'}}

工作配置

{解决: {倒退: {fs:假}}}

有了这个,我就能让我的 JavaScript 解析器工作.

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

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

Error

[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

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.

Versions

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

Update (Oct 29 2020)

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

解决方案

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.

Does not work

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

Working configuration

{
  resolve: {
    fallback: {
      fs: false
    }
  }
}

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

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天全站免登陆