-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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 does not transpile import/export in node_modules #11753
Comments
Hey @maliyshock, Looking at your reproduction, I think you are missing an I believe this is more an issue with 3rd party modules being published untranspiled, than a bug in Jest. |
If i set "transformIgnorePatterns": ["node_modules/(?!(konva)/)"] - it would throw another error Cannot find module 'canvas' from 'node_modules/konva/lib/index-node.js' |
@maliyshock that sounds like a separate issue, and I would refer to their docs where |
I would say it is a general and pretty common JEST issue because Jest for some reason goes and parse all of node modules dependencies, even if there is I would have a possibility to say "hey, Jest work with my functions ONLY, and do not touch anything else" At least that option should be. And right now |
What this pattern says is "don't do transformations for anything inside By default, Jest ignore everything inside But in your case, the module The new error that you are getting, is related to something else (you have to install
It doesn't have to do with trusting or checking anything; Jest needs to understand the code in modules used by code you are testing - and also the relationships between them - in order to work. If you need further help to understand this, please check out some of the following resources: |
Ok, so there is no way to say "jest stop checking anything from node modules"? I still do not understand why jest goes to node modules and check everything there. Let me give an example.
The function So in my test, where I am checking a functionality of |
It doesn't matter that you are not calling a piece of code that uses these directly; in your test you are still importing from a file that imports from |
Ok, thanks. I will check it. It is just... weird. I thought I could use it immediately and it is simple. Now after a few days it seemed to me I had to make all of my functions in separate files in that case... |
I get that the learning curve can be a bit steep when you run into something like this 🙂 For many scenarios, Jest will work really well "out of the box". But it's not possible for it to support every conceivable edge case out there as 'plug-and-play' - and as with any software there will always be some limitations, bugs, or even design flaws. In the case of ESM support, for example, there are a number of considerations that's been holding it back... such as waiting until support for older Node versions is dropped so that newer APIs can be used, or for upstream projects (projects Jest depends on) to add support for certain things. Thankfully Jest is very flexible though; a lot of problems can be solved through configuration/customisation. And if you have trouble with a particular library, like |
Yeah, because konva is the only library in the project that I started to use, I thought jest would be failed on each node modules library that I gonna use in the future. If it is a pretty rare case, ok then, there is might not be any problem with other libraries. |
I would like to chip in and say that I have the same issue as maily. However with the module I've nailed it down to Working configuration:
Non-working configution:
|
Fixed the issue for me. I have also installed the
|
This is going in circles. As has been stated, Jest doesn't touch |
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. |
🐛 Bug Report
This is a copy from #6229 which is closed and not fixed still
Jest throws error "SyntaxError: Cannot use import statement outside a module" for libraries imported from node_modules.
To Reproduce
Steps to reproduce the behavior:
npm install konva
If
import Konva from "konva";
exist in the file from which you are going to import function you want to test by jest it will throw this error.If i set
"transformIgnorePatterns": ["node_modules/"]
- it would not helpIf i set
"transformIgnorePatterns": ["node_modules/(?!(konva)/)"]
- it would throw another errorCannot find module 'canvas' from 'node_modules/konva/lib/index-node.js'
By the way handling those packajes by hand it is really bad idea.
If you install canvas by
npm install canvas
and runnpm run test
again it will throwExpected behavior
Well, you should not get any errors. Also, I think it is overhead, it is unnecessary for Jest to go and check all of the node modules libraries and their dependencies and check them. Right now it works only if you isolate each function to a separate file without any dependencies from node modules.
Link to repl or repo (highly encouraged)
https://github.com/maliyshock/game-of-life
npm install
npm run test
Non of provided solutions from #6229 do not work.
The text was updated successfully, but these errors were encountered: