Skip to content

how to handle JEST error: Cannot find module #442

@gurbela

Description

@gurbela

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions