Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
marek-hanzal opened this issue Jul 13, 2017 · 24 comments · Fixed by #7160
Closed

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

marek-hanzal opened this issue Jul 13, 2017 · 24 comments · Fixed by #7160

Comments

@marek-hanzal
Copy link

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'

  • local install of jest in node_modules directory, called directly or from npm test
  • when cheating createSpy module, it fails on Env module and so on

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.

  • node v8.1.3
  • npm 5.0.3
  • jest v20.0.4
  • windows 10 64bit

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
Copy link
Collaborator

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

@marek-hanzal
Copy link
Author

...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
Copy link
Collaborator

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

@cpojer cpojer closed this as completed Jul 13, 2017
@jvanoostveen
Copy link

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

@marek-hanzal
Copy link
Author

I'm also using TypeScript environemnt.

@Prior99
Copy link

Prior99 commented Jul 17, 2017

I am experiencing the same issue.

@Prior99
Copy link

Prior99 commented Jul 17, 2017

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
Copy link

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

@vjeux
Copy link
Contributor

vjeux commented Aug 9, 2017

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

@vjeux vjeux reopened this Aug 9, 2017
@thymikee
Copy link
Collaborator

thymikee commented Aug 9, 2017

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

@vjeux
Copy link
Contributor

vjeux commented Aug 9, 2017

@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
Copy link
Collaborator

thymikee commented Aug 9, 2017

This needs a fix then, thanks

@marcialca
Copy link

marcialca commented Dec 19, 2017

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
Copy link

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
Copy link

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
Copy link
Member

SimenB commented Aug 23, 2018

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
Copy link
Collaborator

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
Copy link
Member

SimenB commented Aug 24, 2018

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
Copy link
Collaborator

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

@SimenB
Copy link
Member

SimenB commented Sep 11, 2018

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
Copy link
Contributor

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
Copy link
Member

SimenB commented Sep 11, 2018

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 added a commit to SimenB/jest that referenced this issue Oct 14, 2018
SimenB added a commit that referenced this issue Oct 15, 2018
<!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. The two fields below are mandatory. -->

<!-- Please remember to update CHANGELOG.md in the root of the project if you have not done so. -->

## Summary

Inspired by #7158, I finally decided to throw a better error in the cases where people have custom `moduleFileExtension` resulting in more or less obscure errors.

I've tackled 2 different issues here (in separate commits, happy to split them up into separate PRs if you want).

1. If you require a file without the file extension, we try to look for files matching _with_ a file extension and list them out. Also tell the user to either include file extension in the `require` or update `moduleFileExtension`.
2. If `js` is missing from `moduleFileExtension`, jest is unable to inject into the runtime. I decided to throw an explicit configuration error rather than fixing `jest-jasmine`'s `require`, as we'd also need all of our dependencies to do the same (e.g. `source-map` throws if we do `moduleFileExtension: []` now).

Fixes #4025.

<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->

## Test plan
Integration tests added

<!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI. -->
@SimenB
Copy link
Member

SimenB commented Oct 15, 2018

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
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

12 participants