Webpack 5 improperly reuses function containing __dirname

Viewed 24

I have a function that looks like this:

export const baseSourceDir = () => __dirname;

I use it as part of the mechanism that automatically creates unique names for Redux actions and similar stuff, based on the files' paths.

This function exists twice in my structure: once in the app and once in its core dependency package (a node_module). Both functions are supposed to the same thing in general but because __dirname is a magic constant, the results of those functions are supposed to be different (based on the location of the files containing them in the original sources).

This all worked properly in Webpack 4 but after migrating it to Webpack 5, webpack optimized my bundle by reusing the same function twice. They're both called the same, they look the same, but because of that magic constant, they are not the same. When I renamed one of those functions, it all worked again.

Is there a way to either disable that optimization or, preferably, to configure the exception?

0 Answers
Related