无法导入指定的导出“XXX” (作为“XXX”导入)从默认导出模块(仅默认导出可用)

发布于 2025-01-11 02:33:01 字数 1263 浏览 2 评论 0原文

我在将其导入到我的 TypeScript React 项目中时遇到问题。

import { SwapWidget } from '@uniswap/widgets';

在编译yarn build时出现此错误:

Can't import the named export 'SwapWidget' (imported as 'SwapWidget') from default-exporting module (only default export is available)

这是@uniswap\widgets库中的声明:

declare type SwapWidgetProps = SwapProps & WidgetProps;
declare function SwapWidget(props: SwapWidgetProps): JSX.Element;

export { SUPPORTED_LOCALES, SwapWidget };

ts-config.js

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src"
  ]
}

I'm having an issue importing this in my TypeScript React project.

import { SwapWidget } from '@uniswap/widgets';

Getting this error on compilation yarn build:

Can't import the named export 'SwapWidget' (imported as 'SwapWidget') from default-exporting module (only default export is available)

This is the declaration in the @uniswap\widgets library:

declare type SwapWidgetProps = SwapProps & WidgetProps;
declare function SwapWidget(props: SwapWidgetProps): JSX.Element;

export { SUPPORTED_LOCALES, SwapWidget };

ts-config.js:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src"
  ]
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

澉约 2025-01-18 02:33:01

对我来说,这个问题是由我的 webpack 规则之一在 node_modules 中转换文件引起的。

我通过添加排除来修复它:

//webpack.config.js
module.exports = {
...
module:{
  rules:[
    {
      test: /\.(txt|glsl|vert|frag)/,
      type: 'asset/source',
      //add this exclude
      exclude: [/node_modules/],
    },
  ]
}

For me this issue was caused by one of my webpack rules transforming files in node_modules.

I fixed it by adding an exclude:

//webpack.config.js
module.exports = {
...
module:{
  rules:[
    {
      test: /\.(txt|glsl|vert|frag)/,
      type: 'asset/source',
      //add this exclude
      exclude: [/node_modules/],
    },
  ]
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文