Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An import path cannot end with a '.ts' extension. Consider importing 'src/theme.js'

So this error has been a bit of a mystery to me and I'm having trouble figuring out how to resolve it.

I have a theme.ts file that more or less looks like this below:

import { AgnosticStyles, ThemeParameters } from 'styled-components';
import { createTheme } from '@material-ui/core/styles';

const agnosticStyles: AgnosticStyles = {
  font: {
    weight: {
      light: '300',
      normal: '400',
      bold: '600',
    },
  },
};
...
// more themes

const defaultTheme = {
  lightTheme,
  darkTheme,
};

export default defaultTheme;

in my Button.stories.txs file, when I try to import it the same way I import everything else... I get the following error in storybook:

enter image description here

Okay, so I gues I need to then write theme.ts, however that does two things. One, it creates the error shown below and two, it breaks the intellisense that comes with VsCode TS.

enter image description here


How can I fix my Button.stories.tsx file so the import path error with go away and I can just import as src/theme?

like image 287
kevin Avatar asked Dec 06 '25 20:12

kevin


1 Answers

Include your *.tsx files in your tsconfig.json:

{
  "compilerOptions": {
    // ....
  },
  "include": ["**/*.ts", "**/*.tsx"],
  "exclude": ["node_modules"]
}

like image 197
doublesharp Avatar answered Dec 08 '25 10:12

doublesharp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!