Jest: Cannot find module A from B in absolute path

Created on 31 Jan 2018  路  1Comment  路  Source: facebook/jest

Do you want to request a _feature_ or report a _bug_?
bug
What is the current behavior?
While testing react component by jest.
I can meet Cannot find module A from B in absolute path

import Popover from 'common/components/Pop'

moduleNameMapper in jest.config.js

  moduleNameMapper: {
    '\\.(css|scss)$': 'identity-obj-proxy',
    "^common$": "<rootDir>/common$1",
  },

And already aliased in webpack.config.js

When I modified relative path ../../../../common/components/Pop, I could test it.

So, I saw your git history, there are many issues about absolute path.
Are there any problems about it?

If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install and yarn test.

What is the expected behavior?
Can find module A in absolute path

Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.

Jest: 22.0.0
node: 6.5
yarn: 0.27.5

Most helpful comment

Hey @stonezzang

I think you should use the moduleDirectories option as explained in this guide.

A suggested configuration object will look like this:

// package.json
{
  "jest": {
    "moduleDirectories": ["common"],

    "moduleNameMapper": {
      "\\.(css|scss)$": "identity-obj-proxy"
    }
  }
}

>All comments

Hey @stonezzang

I think you should use the moduleDirectories option as explained in this guide.

A suggested configuration object will look like this:

// package.json
{
  "jest": {
    "moduleDirectories": ["common"],

    "moduleNameMapper": {
      "\\.(css|scss)$": "identity-obj-proxy"
    }
  }
}
Was this page helpful?
0 / 5 - 0 ratings