question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jest can't resolve module

See original GitHub issue

Do you want to request a feature or report a bug? Bug

What is the current behavior?

Having such require syntax in sources cause jest error:

const resBundle = require(
  'i18next-resource-store-loader!i18n/locales/index.js'
);

Error:

Test suite failed to run

    Cannot find module 'i18next-resource-store-loader!i18n/locales/index.js' from 'i18n.js'
...

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:169:17)

What is the expected behavior? I want to run my tests !

Please provide your exact Jest configuration

"jest": {
    "coverageDirectory": "./coverage/",
    "collectCoverageFrom": [
      "src/**/*.js"
    ],
    "moduleNameMapper": {
      "\\.(scss|less)$": "identity-obj-proxy"
    },
    "modulePaths": [
      "<rootDir>/src/"
    ],
    "setupFiles": [
      "<rootDir>/src/__mocks__/localStorageMock.js"
    ]
  }

Is there any workarounds ?

Thank you!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

13reactions
SimenBcommented, Apr 12, 2018

See https://facebook.github.io/jest/docs/en/webpack.html

Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

12reactions
SimenBcommented, Apr 13, 2018

No you’re not, you’re trying to use webpack specific syntax outside of webpack, and I linked to the relevant docs

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest gives `Cannot find module` when importing components ...
This Workaround: Using "moduleNameMapper" in your jest configuration will make test-resolve work as expected:
Read more >
jest: configuring jest to resolve modules - code-comments
A common pattern within Javascript applications is to use Webpack or Typescript to treat internal directories as modules so that they can be ......
Read more >
Configuring Jest
Jest will run .mjs and .js files with nearest package.json 's type field set to module as ECMAScript Modules.
Read more >
Configuring Module Resolution On Typescript and Jest
Jest needs a way to figure out how to resolve the modules. We use the moduleNameMapper property to specify module resolution using regular...
Read more >
Webpack and Jest v0.36 Upgrade Guide
Additionally, Jest now uses Node as the default test envirmonment ... with problems: Error: Module not found: Error: Can't resolve 'net' in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found