After updating from @tabler/icons-react 2.47.0 to 3.0.0, I get errors when attempting to bundle my application with Vite.
[vite] Error when evaluating SSR module: failed to import "@tabler/icons-react"
|- ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and 'node_modules/@tabler/icons-react/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at node_modules/@tabler/icons-react/dist/cjs/tabler-icons-react.js:10:13
using main, module, and browser is the old way of doing this. There is also a newer way to do this that you may prefer to use instead: the exports field in package.json.
So exports may be preferable. I haven't tested non-ESM builds, though.
After updating from @tabler/icons-react 2.47.0 to 3.0.0, I get errors when attempting to bundle my application with Vite.
The CJS file is being loaded, not the ESM one. It's only an issue with SSR. Here's a repro: https://stackblitz.com/edit/bluwy-create-vite-extra-2wmmpp?file=src%2FApp.tsx
Are the types wrong? reports issues with the package relating to Node module resolution, which seems to be accurate.
It works if I remove
main
,module
, andtypings
from package.json and replace them withexports
:As esbuild notes in their docs,
So
exports
may be preferable. I haven't tested non-ESM builds, though.