tabler / tabler-icons

A set of over 5400 free MIT-licensed high-quality SVG icons for you to use in your web projects.
https://tabler.io/icons
MIT License
17.84k stars 886 forks source link

`exports` key in @tabler/icons obscures main export #718

Open frabarz opened 1 year ago

frabarz commented 1 year ago

I need to obtain a hashmap of the SVG source strings for the icons, so I'm using the @tabler/icons package. Due to project constraints, I can only use import statement, but when trying to do import * as tablerIcons from "@tabler/icons", I'm getting this error:

'Failed to resolve entry for package "@tabler/icons". The package may have incorrect main/module/exports 
specified in its package.json: Missing "." specifier in "@tabler/icons" package.

This is caused by having the following exports key:

  "exports": {
    "./*": [
      "./icons/*"
    ]
  },

I'm not sure about the spec, but when bundlers see a "exports" in the manifest, they ignore "main" and "module" and abide only by what exports say, and since there's no "." key in there, is not possible to import _ from "@tabler/icons" from the main dist file; this only allows individual imports of the SVG files. Also, as "exports" obscures the whole package contents, is not possible to do import * as icons from "@tabler/icons/dist/es/tabler-icons.js" either.

The solution would be adding this to "exports":

".": ["./dist/es/tabler-icons.js"],
jacktrusler commented 1 year ago

Related: I upgraded from version 1.114.0 to 2.29 today for my next project and I'm getting this error

Package path . is not exported from package <project-path>/node_modules/@tabler/icons (see exports field in <project-path>/node_modules/@tabler/icons/package.json)

Here is the working 1.114.0 Version in the package.json:

"exports": {
    ".": {
      "import": "./icons-react/dist/index.esm.js",
      "require": "./icons-react/dist/index.cjs.js"
    },
    "./iconfont/*": "./iconfont/*",
    "./*": [
      "./icons/*",
      "./icons-png/*"
    ]
  },

And here is the broken 2.29.0 version in the package.json:

"exports": {
    "./*": [
      "./icons/*"
    ]
  },