Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read properties of undefined (reading 'fallback') #38

Open
selfagency opened this issue Sep 16, 2022 · 4 comments
Open

Cannot read properties of undefined (reading 'fallback') #38

selfagency opened this issue Sep 16, 2022 · 4 comments

Comments

@selfagency
Copy link

webpack.config.js

const {TsconfigPathsPlugin} = require('tsconfig-paths-webpack-plugin');
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
const path = require('path');

module.exports = {
  mode: 'production',
  node: {
    global: true,
    __filename: true,
    __dirname: true,
  },
  entry: './index.ts',
  output: {
    path: `${path.resolve(__dirname)}/dist`,
    filename: 'index.js',
    library: {
      type: 'commonjs',
    },
  },
  resolve: {
    plugins: [new NodePolyfillPlugin({
      include: ['path'],
    }), new TsconfigPathsPlugin()],
    extensions: ['.js', '.jsx', '.ts', '.tsx'],
  },
  module: {
    rules: [
      {
        test: /\.ts$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: 'swc-loader',
          options: {
            jsc: {
              parser: {
                syntax: 'typescript',
              },
            },
          },
        },
      },
    ],
  },
};

log output

11:42:29 AM ✖1 » /Users/daniel/.nvm/versions/node/v16.13.2/bin/webpack
assets by status 0 bytes [cached] 1 asset

ERROR in Cannot read properties of undefined (reading 'fallback')

webpack 5.74.0 compiled with 1 error in 72 ms
@Richienb
Copy link
Owner

What happens if you swap the order of the plugins?

@jelling
Copy link

jelling commented Mar 30, 2023

Fwiw I'm using TsconfigPathsPlugin and also have the same issue. Switching the order has no effect.

@Richienb
Copy link
Owner

Richienb commented Apr 2, 2023

Possibly solved by checking if compiler.options.resolve.fallback exists before trying to get its value

compiler.options.resolve.fallback = {
...filter({
assert: require.resolve('assert/'),
buffer: require.resolve('buffer/'),
console: require.resolve('console-browserify'),
constants: require.resolve('constants-browserify'),
crypto: require.resolve('crypto-browserify'),
domain: require.resolve('domain-browser'),
events: require.resolve('events/'),
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
os: require.resolve('os-browserify/browser'),
path: require.resolve('path-browserify'),
punycode: require.resolve('punycode/'),
process: require.resolve('process/browser'),
querystring: require.resolve('querystring-es3'),
stream: require.resolve('stream-browserify'),
/* eslint-disable camelcase */
_stream_duplex: require.resolve('readable-stream/lib/_stream_duplex'),
_stream_passthrough: require.resolve('readable-stream/lib/_stream_passthrough'),
_stream_readable: require.resolve('readable-stream/lib/_stream_readable'),
_stream_transform: require.resolve('readable-stream/lib/_stream_transform'),
_stream_writable: require.resolve('readable-stream/lib/_stream_writable'),
string_decoder: require.resolve('string_decoder/'),
/* eslint-enable camelcase */
sys: require.resolve('util/'),
timers: require.resolve('timers-browserify'),
tty: require.resolve('tty-browserify'),
url: require.resolve('url/'),
util: require.resolve('util/'),
vm: require.resolve('vm-browserify'),
zlib: require.resolve('browserify-zlib')
}),
...compiler.options.resolve.fallback

@csdebruin
Copy link

Had the same issue, in my case:

module.exports = {
  ...
   resolve: {
    ...
    plugins: [new NodePolyfillPlugin()]
  }
}

Should be:

module.exports = {
  ...
  resolve: {
    ..
  },
  plugins: [new NodePolyfillPlugin()]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants