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.

Test suite failed to run - Cannot find module

See original GitHub issue

Environment

  1. node -v: v8.11.3
  2. npm -v: 5.6.0
  3. npm ls jest or npm ls react-scripts (if you haven’t ejected):
   $ npm ls jest
   /Users/hnjoshi/repos/my-app/content/private/react
   └── jest@23.3.0
  1. your vscode-jest settings if customized:
  "jest.runAllTestsFirst": false,
  "jest.debugMode": true,
  "jest.pathToJest": "jest",
  "jest.pathToConfig": "/Users/hnjoshi/repos/my-app/content/private/react/package.json"
  1. Operating system: MacOS High Sierra, 10.13.6 (17G65)

Prerequisite

  • are you able to run jest test from command line? [yes]
  • how do yo run your tests from command line? npm run test

Steps to Reproduce

rootDir/content/private/react/package.json - npm run test works fine from command line

  "scripts": {
    "test": "jest --no-cache",
    "test:coverage": "jest --coverage --no-cache",
    "test-watch": "jest --watch",
    "watch": "webpack --progress --watch"
  },
  "jest": {
    "cacheDirectory": "cache",
    "collectCoverageFrom": [
      "**/*.js",
      "!**/eslint-plugin-control/**",
      "!**/node_modules/**",
      "!**/coverage/**",
      "!webpack.config.js"
    ],
    "moduleNameMapper": {
      "^.+\\.(scss)$": "<rootDir>/__mocks__/styleMock.js"
    },
    "testRegex": "/__tests__/[^.].*js$",
    "setupFiles": [
      "<rootDir>/setup-jest.js",
      "<rootDir>/__mocks__/localStorageMock.js"
    ],
    "setupTestFrameworkScriptFile": "<rootDir>/setup-adapter.js",
    "snapshotSerializers": [
      "<rootDir>/node_modules/enzyme-to-json/serializer"
    ],
    "testEnvironment": "jest-environment-jsdom-global"
  }

rootDir/content/private/react/components/ - Test files are in this directory

Relevant Debug Info

I think there is some issue with the --include-path but I could not tell what script is being executed when I save the test file.

Expected Behavior when test file is saved

Tests should pass or fail for all test suites related to changed files in the Output window.

Actual Behavior

FAIL content/private/react/components/User/Details/__tests__/Details-test.js

  ● Test suite failed to run

    Cannot find module 'components/Name' from 'index.js'

      1 | import PropTypes from 'prop-types';
      2 | import React from 'react';
    > 3 | import Name from 'components/Name';
        | ^
      4 | import Input from 'components/Input';
      5 | import {
      6 |   Form,

      at Resolver.resolveModule (../../../../../../../usr/local/lib/node_modules/jest/node_modules/jest-resolve/build/index.js:221:17)
      at Object.<anonymous> (components/User/Details/index.js:3:1)


Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.542s
Ran all test suites related to changed files.

The fastest (and the most fun) way to resolve the issue is to submit a pull-request yourself. If you are interested, feel free to check out the contribution guide, we look forward to seeing your PR…

Issue Analytics

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

github_iconTop GitHub Comments

198reactions
escatoncommented, Sep 24, 2018

Try to add this to jest config

"modulePaths": [
  "<rootDir>"
],
98reactions
HassanNemircommented, Jun 5, 2019

@escaton still doesn’t work for me

Read more comments on GitHub >

github_iconTop Results From Across the Web

typescript - Test suite failed to run Cannot find module or its ...
I solved this by clearing jest cache see this answer here.
Read more >
jest test suite failed to run cannot find module - You.com
The weird thing I experienced is, I grepped the package.json files of all modules in my node_modules directory, and couldn't find any core-js...
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 >
Test suite failed to run Cannot find module 'lightning ...
Test suite failed to run Cannot find module 'lightning/messageService' from 'exOppTradelineLists.js. I am getting the above error when i am ...
Read more >
Configuring Module Resolution On Typescript and Jest
If you tried running the tests any time until now, it probably failed to run and threw an error: Cannot find module '@/repositories/person'...
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