Webpack Error - configuration.node has an unknown property 'fs'

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.


Next.js users:

module.exports = {
  webpack: (config, { isServer }) => {
    if (!isServer) {
      config.resolve.fallback.fs = false;
    }
    return config;
  },
}

Source


I have encountered with same issue while working with Next js, I have searched different solutions like webpack5: false or fs: false, but that didn't work for me.

config.node = {
  // fs: 'empty'
  global: true,
  __filename: true,
  __dirname: true,
}

this did work for me, because in webpack 3.0.0, the node option may be set to false to completely turn off the NodeStuffPlugin, as we are working in JS and specially in Next-JS which requires Node-JS, so we don't have to turn it off completely because while 'false' the Webpack wouldn't touch your '__filename' code and your '__dirname' code.

Any correction or guidance's will be appreciated, Thankyou


Exactly for rails webpacker, if you are using it, the solution should be a:

Inside any of config/webpack/*.js which uses the plain custom config (see https://github.com/rails/webpacker#webpack-configuration for more), just add the code resolving and removing the node property.

const { environment } = require('@rails/webpacker')

const customConfig = {
  resolve: {
    fallback: {
      dgram: false,
      fs: false,
      net: false,
      tls: false,
      child_process: false
    }
  }
};

environment.config.delete('node.dgram')
environment.config.delete('node.fs')
environment.config.delete('node.net')
environment.config.delete('node.tls')
environment.config.delete('node.child_process')

environment.config.merge(customConfig);

module.exports = environment