I recently upgraded from Webpack 4 to 5 and followed the instructions in the README, added in 6dc8265e24788b70add4e2bf50fd1a13581d18af:
Note: For Webpack 5, replace target: 'node' with the externalsPreset object:
However, I found that the bundle created used the browser versions of third-party modules that it ended up including (e.g. the ones I specified in my allowlist), rather than the node-based versions. An example of this is cuid, which included its fingerprint.browser.js (and which threw an exception upon import, since it expected a browser environment and didn't find one).
Once I re-added target: 'node' to my webpack configuration, the bundle no longer used the browser versions of dependencies, and everything worked okay.
So I might be wrong here, but maybe better advice is to add the externalsPreset object in addition to keepingtarget: 'node'?
I recently upgraded from Webpack 4 to 5 and followed the instructions in the README, added in 6dc8265e24788b70add4e2bf50fd1a13581d18af:
However, I found that the bundle created used the browser versions of third-party modules that it ended up including (e.g. the ones I specified in my
allowlist
), rather than the node-based versions. An example of this is cuid, which included itsfingerprint.browser.js
(and which threw an exception upon import, since it expected a browser environment and didn't find one).Once I re-added
target: 'node'
to my webpack configuration, the bundle no longer used the browser versions of dependencies, and everything worked okay.So I might be wrong here, but maybe better advice is to add the
externalsPreset
object in addition to keepingtarget: 'node'
?