sindresorhus / irregular-plurals

Map of nouns to their irregular plural form
MIT License
83 stars 24 forks source link

Issue with exports when minified #24

Closed strblr closed 1 year ago

strblr commented 1 year ago

Hello,

After switching from CRA to Vite on a big project, I got a cryptic error: fje.has" is not a function. After tracking down the bug, I found that it was caused by this line in plur:

https://github.com/sindresorhus/plur/blob/main/index.js#L8

if (irregularPlurals.has(word.toLowerCase())) {

irregularPlurals is of course a direct import from this package:

https://github.com/sindresorhus/irregular-plurals/blob/main/index.js#L5-L9

Object.defineProperty(module, 'exports', {
    get() {
        return new Map(Object.entries(irregularPlurals));
    }
});

This gets minified as an empty object export by both esbuild and terser (I've tried both). Thus the error.

I saw here that you put the responsibility on Vite: https://github.com/sindresorhus/plur/issues/32 I believe this has nothing to do with Vite as it would happen with anyone using just esbuild or terser. This is also the only package that causes this, and I have thousands in this project, counting dependencies of dependencies. Getting rid of plur (thus irregular-plurals) just made the whole app work.