无法在 React 应用程序中导入 Tabler 包(错误:包路径 . 未从包中导出)

gog*_*g99 4 node.js node-modules typescript reactjs

我正在 React 组件中导入一些 Tabler 图标:

功能卡.tsx

import { IconGauge, IconUser, IconCookie } from '@tabler/icons';
Run Code Online (Sandbox Code Playgroud)

不幸的是我收到以下错误:

ERROR in ./src/components/FeatureCards.tsx 6:0-64

Module not found: Error: Package path . is not exported from package /xx/App/node_modules/@tabler/icons (see exports field in /xx/App/node_modules/@tabler/icons/package.json)
Run Code Online (Sandbox Code Playgroud)

在 /xx/App/node_modules/@tabler/icons/ package.json中,导出如下所示:

  "exports": {
    "./*": [
      "./icons/*"
    ]
  },
Run Code Online (Sandbox Code Playgroud)

我尝试将其更改为..:

 "exports": {
    "./*": [
      "./icons/*"
    ],
    ".": "./icons"
  },
Run Code Online (Sandbox Code Playgroud)

..根据网上的建议,但这给出了新的错误:

Module not found: Error: Can't resolve '@tabler/icons' in '/xx/App/src/components'

Run Code Online (Sandbox Code Playgroud)

我还尝试删除并重新安装我的节点模块,但没有成功。假设这是版本问题,我将暂时降级。

预先感谢您的任何建议。

编辑:将 tabler 降级至 1.115.0 目前已解决该问题。

npm  i @tabler/icons@1.115.0
Run Code Online (Sandbox Code Playgroud)

小智 5

你应该使用@tabler/icons-react