Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to handle JEST error: Cannot find module #442

Open
gurbela opened this issue Feb 6, 2023 · 1 comment
Open

how to handle JEST error: Cannot find module #442

gurbela opened this issue Feb 6, 2023 · 1 comment

Comments

@gurbela
Copy link

gurbela commented Feb 6, 2023

When I run yarn jest I got this error: Cannot find module '@img/test.svg' from 'src/screens/TestScreen/TestScreen.tsx'

I'm trying to import SVG-s from a folder, the import works fine, but I only have this problem on JEST.

"react-native": "0.64.4",
"babel-preset-react-native": "4.0.1",

my babel.config.js:

module.exports = {
   presets: ['module:metro-react-native-babel-preset'],
   plugins: [
      [
         'module-resolver',
         {
            root: ['./src'],
            alias: [
               {
                  '@img': './assets/images/',
               },
               {
                  '@tab': './assets/images/tabIcons/',
               },
            ],
         },
         '@babel/plugin-transform-modules-commonjs',
      ],
   ],
};

tsconfig:

"baseUrl": "./src",
"paths": {
      "@img": ["./assets/images/"],
      "@tab": ["./assets/images/tabIcons/"],
}, 

declarations.d.ts:

declare module '*.svg' {
   import {SvgProps} from 'react-native-svg';
   const content: React.FC<SvgProps>;
   export default content;
}
@KeflemTrindade
Copy link

Did you get a solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants