首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法从默认导出模块导入命名的导出'XXX‘(导入为'XXX') (只有默认导出可用)

无法从默认导出模块导入命名的导出'XXX‘(导入为'XXX') (只有默认导出可用)
EN

Stack Overflow用户
提问于 2022-02-28 17:55:11
回答 1查看 2.3K关注 0票数 5

在我的TypeScript React项目中导入这个有问题。

代码语言:javascript
复制
import { SwapWidget } from '@uniswap/widgets';

在编译yarn build时获取此错误

代码语言:javascript
复制
Can't import the named export 'SwapWidget' (imported as 'SwapWidget') from default-exporting module (only default export is available)

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

代码语言:javascript
复制
declare type SwapWidgetProps = SwapProps & WidgetProps;
declare function SwapWidget(props: SwapWidgetProps): JSX.Element;

export { SUPPORTED_LOCALES, SwapWidget };

ts-config.js

代码语言:javascript
复制
{
  "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"
  ]
}
EN

回答 1

Stack Overflow用户

发布于 2022-07-10 09:27:44

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

我修正了它,增加了一个排除:

代码语言:javascript
复制
//webpack.config.js
module.exports = {
...
module:{
  rules:[
    {
      test: /\.(txt|glsl|vert|frag)/,
      type: 'asset/source',
      //add this exclude
      exclude: [/node_modules/],
    },
  ]
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71299100

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档