无法导入指定的导出“XXX” (作为“XXX”导入)从默认导出模块(仅默认导出可用)
我在将其导入到我的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对我来说,这个问题是由我的 webpack 规则之一在
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: