6

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"
  ]
}
Evandro Pomatti
  • 13,341
  • 16
  • 97
  • 165
  • Is this coming typescript or your compiled code when you try to run it? If the latter, how are you compiling this code? What bundler are using? – Alex Wayne Feb 28 '22 at 18:57
  • Hey, it's on compile time. I bootstrapped my project with `npx create-react-app . --template typescript` and the problem shows in `yarn build` – Evandro Pomatti Feb 28 '22 at 18:59

1 Answers1

1

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/],
    },
  ]
}
chantey
  • 4,252
  • 1
  • 35
  • 40