79078355

Date: 2024-10-11 13:09:28
Score: 2
Natty:
Report link

I was doing 2 things incorrectly. One was using a plugin in babelrc that transforms ECMAScript modules to CommonJS which was generating require statements in the build file. Removing this plugin from babel was one of the fixes required.

Plugin was - @babel/plugin-transform-modules-commonjs

Another thing was how webpack was handling externals. For setting node_modules as externals we made use of nodeExternals which is a part of webpack-node-externals package. This, by design, uses require to import these external packages at runtime. This can be changed by setting the importType property in nodeExternals:

nodeExternals({
      importType: 'module',
      allowlist: [/\.(?!(?:jsx?|json)$).{1,5}$/i, /react-toolbox/],
}),

This results in a build file which does not use require to fetch external packages and hence is compatible with ES module.

Reasons:
  • Blacklisted phrase (1): this plugin
  • Contains signature (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Exter