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'
npm test
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"
}
Please provide repro, so someone with Windows setup can triage this.
...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.
Sad to hear it didn't work out. We would definitely use some help on making Windows support better.
I have this error as well, on macOS X.
Tried Jest with a new project/setup, using the TypeScript setup.
I'm also using TypeScript environemnt.
I am experiencing the same issue.
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.
I suffered the same problem on Linux machine. @Prior99 suggestion solved my problem.
I've also ran into it and @Prior99 solution fixed it. Fixing it or a better error message would be awesome!
@vjeux usually removing jest from node_modules (or all node_modules) and installing new version again helps on case insensitive (macOS here) machines.
@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.
This needs a fix then, thanks
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
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
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
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?
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.
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.
Oh yea, it makes sense to show it when throwing error 👍
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
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 ?
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
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!
Most helpful comment
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.