在我的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"
]
}发布于 2022-07-10 09:27:44
对我来说,这个问题是由我的webpack规则在node_modules中转换文件引起的。
我修正了它,增加了一个排除:
//webpack.config.js
module.exports = {
...
module:{
rules:[
{
test: /\.(txt|glsl|vert|frag)/,
type: 'asset/source',
//add this exclude
exclude: [/node_modules/],
},
]
}https://stackoverflow.com/questions/71299100
复制相似问题