Home > Software design >  Cannot export module, but import is fine
Cannot export module, but import is fine

Time:09-27

Why this work

import ActionButton from './components/atom/ActionButton'

And this not?

export ActionButton from './components/atom/ActionButton'

The line above give me the error:

Cannot find name 'ActionButton'.ts(2304)

My directory structure

.
├── components
│   ├── atom
│   │   ├── ActionButton
│   │   │   ├── ActionButton.spec.tsx
│   │   │   ├── ActionButton.stories.tsx
│   │   │   ├── ActionButton.styles.tsx
│   │   │   ├── ActionButton.tsx
│   │   │   └── index.ts

Where on index.ts I have

export { default } from './ActionButton'

CodePudding user response:

Change it to export { default as ActionButton } from './components/atom/ActionButton' as ActionButton has no named export.

  • Related