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

babel-jest module isn't found if not added directly #273

Closed
IlCallo opened this issue May 28, 2019 · 9 comments · Fixed by #285
Closed

babel-jest module isn't found if not added directly #273

IlCallo opened this issue May 28, 2019 · 9 comments · Fixed by #285

Comments

@IlCallo
Copy link
Contributor

IlCallo commented May 28, 2019

Hi guys, I noticed today that I cannot run tests anymore if I have setup Babel transpilation for JS files.

I get this error

● Validation Error:

  Module babel-jest in the transform option was not found.
         <rootDir> is: D:\Sources\smile80\libs\renderer

  Configuration Documentation:
  https://jestjs.io/docs/configuration.html

I checked my yarn.lock file and babel-jest is actually present in the file, but there's no folder into node_modules, that may be the cause.
Lately I upgraded to yarn 1.16.0, so I tried downgrading to 1.15.2, but with no results: same error.

If I add it as a direct dependency, it restarts working.
I'm pretty confused right now, I checked my history and I'm pretty sure that 2 days ago I launched my tests without problems and without babel-jest as direct dependency.

@wtho
Copy link
Collaborator

wtho commented May 28, 2019

The reason might be that some/several other packages had babel-jest as a dependency and something about that changed. Sometimes, if possible, packages get deduped by npm/yarn to save space and are therefore put in the root of node_modules only once, if several other package use a compatible common version.

If this is not the case, each package might have its inner node_modules folder with the respective version of the dependency.

As npm heavily relies on semantic versioning, even running npm on the same day can/will result in different packages (if some package somewhere in the dependency tree changed just a minor version) and deduped packages might not be in the root anymore, as they were yesterday.

A general rule of thumb is: if a package is imported/required directly by your project, it should be declared in package.json.

@IlCallo
Copy link
Contributor Author

IlCallo commented May 28, 2019

Make sense, even if it should be a rare occurring: all my dependencies are version-locked.

That said, maybe it should be added, in the section I linky l linked, that you have to install babel-jest as direct dev-dependency

@thymikee
Copy link
Owner

If babel is used in any way, babel-jest is required by Jest to be in your dev dependencies. It's in the docs on Babel integration. Feel free to add a note

@wtho
Copy link
Collaborator

wtho commented Jun 1, 2019

all my dependencies are version-locked

Just to avoid confusion, version-locking in npm can only be achieved by installing packages only using npm ci after package-lock.json, which will install the exact versions described in package-lock.json.

Anyway, I will close this issue for now, feel free to reopen in case you feel this is unresolved.

@wtho wtho closed this as completed Jun 1, 2019
@IlCallo
Copy link
Contributor Author

IlCallo commented Jun 1, 2019

I use yarn, I think that behaviour is the default.

I'll PR a note on the readme as soon as I have some time to add the note

@wtho
Copy link
Collaborator

wtho commented Jun 1, 2019

Oh yeah, yarn is locked to yarn.lock as long as the dependencies in package.json do not change.

@IlCallo
Copy link
Contributor Author

IlCallo commented Jun 10, 2019

If babel is used in any way, babel-jest is required by Jest to be in your dev dependencies. It's in the docs on Babel integration. Feel free to add a note

I guess you meant the first line of this page.
I'll open a PR adding the link to that page

@inlightmedia
Copy link

I ran into this when using yarn workspaces. One of my packages was using babel-jest for testing but when I added babel-jest to the package.json it would add to the repo's root yarn.lock file and not to the node_modules folder of the package. In my jest transform I was referencing babel-jest like this:

transform: {
        "^.+\\.(js|jsx|ts|tsx)$": "./node_modules/.bin/babel-jest",
},

To fix, I just removed the relative path:

transform: {
        "^.+\\.(js|jsx|ts|tsx)$": "babel-jest",
},

@aManNamedJed
Copy link

@inlightmedia Not all heroes wear capes, or perhaps you do, in which case I like you even more. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants