jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.21k stars 6.46k forks source link

Bug: Cannot find module './createSpy' from 'jasmine-light.js' #4025

Closed marek-hanzal closed 6 years ago

marek-hanzal commented 7 years ago

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

Bug.

What is the current behavior?

Cannot find module './createSpy' from 'jasmine-light.js'

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?

Tests run without en error.

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

jest --showConfig:

{
  "config": {
    "automock": false,
    "browser": false,
    "cache": true,
    "cacheDirectory": "C:\\Users\\MAREKH~1\\AppData\\Local\\Temp\\jest",
    "clearMocks": false,
    "coveragePathIgnorePatterns": [
      "\\\\node_modules\\\\"
    ],
    "globals": {
      "ts-jest": {
        "tsConfigFile": "test/tsconfig.json",
        "skipBabel": true
      }
    },
    "haste": {
      "providesModuleNodeModules": []
    },
    "moduleDirectories": [
      "node_modules"
    ],
    "moduleFileExtensions": [
      "ts"
    ],
    "moduleNameMapper": {},
    "modulePathIgnorePatterns": [],
    "name": "aa9b43f456cf36d229d63d785a874457",
    "resetMocks": false,
    "resetModules": false,
    "rootDir": "C:\\projects\\edde-framework\\edde-js",
    "roots": [
      "C:\\projects\\edde-framework\\edde-js"
    ],
    "setupFiles": [],
    "snapshotSerializers": [],
    "testEnvironment": "jest-environment-jsdom",
    "testMatch": [],
    "testPathIgnorePatterns": [
      "\\\\node_modules\\\\"
    ],
    "testRegex": "(/test/.*|\\.spec)\\.ts$",
    "testRunner": "C:\\projects\\edde-framework\\edde-js\\node_modules\\jest-jasmine2\\build\\index.js",
    "testURL": "about:blank",
    "timers": "real",
    "transform": [
      [
        "^.+\\.tsx?$",
        "C:\\projects\\edde-framework\\edde-js\\node_modules\\ts-jest\\preprocessor.js"
      ]
    ],
    "transformIgnorePatterns": [
      "\\\\node_modules\\\\"
    ]
  },
  "framework": "jasmine2",
  "globalConfig": {
    "bail": true,
    "collectCoverage": true,
    "collectCoverageFrom": [
      "src/**"
    ],
    "coverageDirectory": "C:\\projects\\edde-framework\\edde-js\\coverage",
    "coverageReporters": [
      "text-summary"
    ],
    "coverageThreshold": {
      "global": {
        "branches": 50,
        "functions": 50,
        "lines": 50,
        "statements": 50
      }
    },
    "expand": false,
    "mapCoverage": true,
    "noStackTrace": false,
    "notify": false,
    "projects": [
      "C:/projects/edde-framework/edde-js"
    ],
    "rootDir": "C:\\projects\\edde-framework\\edde-js",
    "testPathPattern": "",
    "testResultsProcessor": null,
    "updateSnapshot": "new",
    "useStderr": false,
    "verbose": false,
    "watch": false,
    "watchman": true
  },
  "version": "20.0.4"
}
thymikee commented 7 years ago

Please provide repro, so someone with Windows setup can triage this.

marek-hanzal commented 7 years ago

...I was just trying simple install as docs describes, but I moved to avajs as it was painless to install and run. I'm sorry for disturbing you.

Maybe it was problem only of my setup; if you want, you can close the issue or I can try to find, how I had the previous setup and repo state.

thymikee commented 7 years ago

Sad to hear it didn't work out. We would definitely use some help on making Windows support better.

jvanoostveen commented 7 years ago

I have this error as well, on macOS X. Tried Jest with a new project/setup, using the TypeScript setup.

marek-hanzal commented 7 years ago

I'm also using TypeScript environemnt.

Prior99 commented 7 years ago

I am experiencing the same issue.

Prior99 commented 7 years ago

I found the issue. I removed "js" as a file extension from the Jest config as I only have "ts" files. You cannot do that. Adding "js" again solves the problem for me.

michalvankodev commented 7 years ago

I suffered the same problem on Linux machine. @Prior99 suggestion solved my problem.

vjeux commented 7 years ago

I've also ran into it and @Prior99 solution fixed it. Fixing it or a better error message would be awesome!

thymikee commented 7 years ago

@vjeux usually removing jest from node_modules (or all node_modules) and installing new version again helps on case insensitive (macOS here) machines.

vjeux commented 7 years ago

@thymikee the problem is that jasmine-light.js is bundled with jest and no longer being required if js is not in moduleFileExtensions. To repro, just put "moduleFileExtensions": ["xx"] in your package.json and try to test a .xx file.

thymikee commented 7 years ago

This needs a fix then, thanks

marcialca commented 6 years ago

Is there a temporary fix for this? I'm having issues with it and removing node_modules and reinstalling doesn't seem to fix it for me, neither adding the "js" file extension. It only happens to me when I use a custom resolver

EDIT: Added a new issue with examples for this

ShintaroNippon commented 6 years ago

Hello, these solutions i couldnt apply... i still have the error can someone help please

Cannot find module './create_spy' from 'jasmine_light.js' #5629

ShintaroNippon commented 6 years ago

i have changed the configuration jest to

"jest": { "transform": { ".*": "./tests/preprocessor.js" }, "modulePaths": [ "src" ], "testPathIgnorePatterns": [ "/node_modules/", "/vendor" ], "testRegex": "\.spec\.js" } but then im getting an error

FAIL tests/state-functions.spec.js ● Test suite failed to run

Your test suite must contain at least one test.

at node_modules/jest-cli/build/test_scheduler.js:108:22

SimenB commented 6 years ago

I wonder if we should check for <fileRequired>.* and print a list if any of them exists and tell the user to fix their moduleFileExtensions?

And in addition just be explicit with Jest's own files which are required inside the sandbox.

@thymikee @rickhanlonii thoughts on that?

thymikee commented 6 years ago

Would be best for moduleFileExtensions not affecting Jest internals. Not sure about printing the list, it would slow down resolution a lot and cause a lot of false-positives, don't you think? We could however warn once if there's no js in moduleFileExtensions, just not to be too annoying when using Jest to run non-js.

SimenB commented 6 years ago

Would be best for moduleFileExtensions not affecting Jest internals.

Sure, but as long as jasmine, or circus, is injected into the sandbox, it's hard for user code and config not to. It's why we do the whole fun with Promises.

Not sure about printing the list, it would slow down resolution a lot and cause a lot of false-positives, don't you think?

Would it be slow? I thought maybe we'd have the files in hastefs already, maybe not. And it's already at a point where you're getting an error, spending some IO to try to give a more helpful error in that case seems reasonable to me. It wouldn't run in the happy case.

The thing is that ESM requires the extension, IIRC, while node does not, so I'm not sure about warning about "hey, you're missing js in moduleFileExtension". Maybe that's pedantic, though.

thymikee commented 6 years ago

Oh yea, it makes sense to show it when throwing error 👍

SimenB commented 6 years ago

Whenever someone gets to this, we should also check if there is file casing inconsistency to throw better errors on case sensitive systems then might work locally

endiliey commented 6 years ago

I am not sure if this is related. I got this error (although randomly) when running jest on WSL (Window Subsystem for Linux). But running it on Ubuntu works fine.

@simenB could this be related ?

SimenB commented 6 years ago

Not if you're getting in randomly, no - this issue is for an error in configuration (or typo in require/import). If the error isn't consistent, it's something else

SimenB commented 6 years ago

Whenever someone gets to this, we should also check if there is file casing inconsistency to throw better errors on case sensitive systems then might work locally

Hah, forgot this... If anyone wants to send a PR for this, feel free!

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.