-
-
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
24.1.0: TypeError: Cannot read property 'cwd' of undefined #7868
Comments
Might be. This needs a proper reproduction, though. @SethDavenport mind putting together a more complete project we can pull down and test? As minimal as possible, although it should be fairly easy to debug bigger projects here as well 🙂 If it's hard to isolate, you can change this to just be |
@jeysal it still happens without the setupfile, yes. |
@SimenB it might be tricky to extract. I'll take a shot this evening. In the meantime the change you suggested to
|
I can confirm the same issue occurring for me in a starter react-setup package I am working on, which is hopefully simple enough to allow for debugging. https://github.com/Oliphaunte/react_redux_setup I can also confirm the updates @SethDavenport made in |
Same bug occured in my project. For the detailed info:
|
Same thing on mine :
I am testing the header.js component, and my test resides in header.test.js :
Any ideas what could be wrong? |
Thanks for making a repro repo @Oliphaunte - oddly my attempt to do so didn't reproduce the issue so I'm no closer to understanding what about my environment is triggering it. I did come up with a slightly better workaround than editing my node_modules: const c = {
presets: [
'@babel/preset-env',
'@babel/react',
],
plugins: [
'@babel/plugin-transform-flow-strip-types',
'dynamic-import-node',
'styled-components',
'@babel/plugin-transform-object-assign',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-transform-async-to-generator',
],
sourceMaps: 'inline',
};
const defaultCwd = process.cwd();
const transformer = require('babel-jest').createTransformer(c);
// Monkey patch around https://github.com/facebook/jest/issues/7868
const oldGetCacheKey = transformer.getCacheKey;
transformer.getCacheKey = (
fileData,
filename,
configString,
{ config, instrument, rootDir },
) =>
oldGetCacheKey(
fileData,
filename,
configString, {
config: config || { cwd: defaultCwd },
instrument,
rootDir,
},
);
module.exports = transformer; |
@Oliphaunte your reproduction uses I wonder if we should have a peer dep? |
@SethDavenport Can you verify the version of |
@SimenB I am not explicitly pulling in My yarn.lock has both 23.6.0 and 24.1.0 of jest-runtime, likely due to a downstream dependency using jest 23. |
No, you shouldn't have to. What does your package.json look like? |
Although version 24 of |
ts-jest has issues with jest 24 if you also use babel, from my understanding. So ts-jest and babel-jest@24 does not play well together |
Still broken for me on jest@24 babel-jest@24. =( |
Reproduction? Just saying it's broken doesn't really help us track it down |
I was able to reproduce it, i was trying to fix it for my teammate, i didn't have it initially but after i deleted my node modules i was affected by this issue too |
Sorry I've been slammed this week and didn't get a chance to circle back until now. My best guess at what's going on is as follows: The top-level repo uses Jest 24: ...
"@babel/core": "^7.2.2",
"@babel/plugin-proposal-class-properties": "^7.3.0",
"@babel/plugin-proposal-object-rest-spread": "^7.3.2",
"@babel/plugin-transform-async-to-generator": "^7.2.0",
"@babel/plugin-transform-flow-strip-types": "^7.2.3",
"@babel/plugin-transform-object-assign": "^7.2.0",
"@babel/preset-env": "^7.3.1",
"@babel/preset-react": "^7.0.0",
"babel-jest": "^24.1.0",
"jest": "^24.1.0", However one of its other dependencies uses babel 6/jest 23 (I'm in the middle of porting our internal stack over to Babel 7 and I haven't done our downstream internal packages yet). Crucially this dependency is declaring jest as a I think this is enough for my yarn.lock to have both 23- and 24-series of the jest stack in it, which probably means my runtime env isn't sane. I removed bad internal dependency and now I can run the tests without the error. AFAIC you can close the bug, I just need to finish porting over our internal packages. |
Cool, thanks! Too bad the wrong versions are hoisted... Possibly an npm/yarn bug? |
For any who might encounter this, make sure anything jest related is upgraded to the same major version. Just having jest-cli still on an old version caused this exact error for me. |
I'm getting this error too. I went through the whole package.json and package-lock.json and everything appears to be at v24 for anything related to Jest. This is the error I'm getting:
This is my package.json
|
I went through my versions on package.json and package-lock.json just to double check, and they were all pointing to v24 and above, and I still got the same error. |
Just to update this. I was able to find a workaround by moving jest and babel-jest to versions 20.0.4. I don't see this as a solution per se to the current versions issue, but it at least allowed me to continue my work for the time being. |
If you can put together a reproducible demo I'd be happy to take a look :) |
@SimenB ok great! I'll be working on that repo today, so I'll upgrade everything and report back. Thanks for the pointer! For my own sake, I'm kind of new to this coding stuff, where would I find the documentation on what dependencies are needed for Jest so I don't run into this again? I'm digging through this but with 4000+ dependencies it seems a bit difficult to track all those. Is there a best practices way for checking dependencies? |
In this case, the docs should help you out: https://jestjs.io/docs/en/getting-started#using-babel I think you'll also be seeing a peer dependency warning, not sure about that one, though! |
@SimenB ok so when I run "npm run test" of which the script is ""test": "jest && exit 0" in my package.json, the tests are able to run, but I get an error at the end of it.
If I run simply 'jest' at the command line I get the following again:
I think I have everything set up correctly in my package.json, .babelrc. package.json:
and .babelrc
Am I missing something? Why would "npm run test" work, but not simply 'jest'? |
@SimenB actually, thanks! I think I just figured it out, I also updated the global jest install to the latest version and it worked. |
This problem just recently popped up for me 5 days ago in my jenkins pipeline thus breaking my build, although tests are working on my local machine. Any ideas? |
You don't have a lockfile? As mentioned above, this is dues to version mismatches between Jest dependencies. Without a reproduction, there's not much else we can do to help |
Thanks yes I thought the lockfile prevented these issues from occuring that was the whole idea. Will see if anything has happened along the way. |
But it seems to just randomly appear I'm clueless. As the test where working just fine and then there was a commit in a branch that had nothing to do with the lockfile nor any dependencies. After that all tests just stopped working in any branches.. could it be that the pipeline is storing some dependencies somewhere? What could possibly have happened to the jenkins pipeline along the way? |
I have never used Jenkins, so I am zero help there. However, this is not the issue to discuss it. StackOverflow might be of help? |
Okey so here is how I fixed the issue on the failing tests in my jenkins pipeline (and working locally):
On a retrospective I believe the issue that occurred in my particular case was that there was some new dependency to babel-jest that crashed as I was using the ^ prefix for my dependencies. Changing to a particular version should ensure that this does not happen again and I can choose to update each package as I feel comfortable. It is also worth mentioning I am using a non ejected create-react-app with react-app-rewired conf and prior to the crash I did not have babel-jest in my dev dependencies so not sure what kind of version cra was using under the hood. My conclusion is that something auto-magically broke my dependencies due to this fact that something was updated under the hood. Anyway I'm glad to get this working after just 1.5 days of trial and error. It could have been much worse. |
I'll like to add a resolution if it helps since it took me a day to find out why I was getting this issue: -> in my home directory i had some old node_modules installed that i forgot about |
If you are using node version manager, be sure to look in ~/.nvm What fixed it for me was removing nvm, and installing jest-cli to get the right version of jest |
I'm having this issue in 24.7.1.
Looking at that directory I can confirm not #3391, I definitely have 24.7.1 installed. |
Same here with ts-jest@24.0.2 @jest/core@24.8.0 |
I resolved mine by removing jest.
Now all I have that is jest dependant is :
"babel-jest": "^24.7.1",
"jest-cli": "^24.7.1",
"jest-dom": "^3.1.3",
…On Wed, May 22, 2019 at 9:01 AM Janne Kurkinen ***@***.***> wrote:
Same here with ***@***.*** @***@***.***
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#7868>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAS5DVVNUJZ7R55INLWNU3LPWT4WVANCNFSM4GWWRZTA>
.
|
Fixed this issue by bumping the following packages:
|
The only thing that helped me with this issue was downgrading I've found the answer here https://stackoverflow.com/questions/54707877/typeerror-cannot-read-property-cwd-of-undefined. Thank you, Cesare Fischetti! |
Same here I had to downgrade babel-jest from 24.8.0 to 23.4.2. |
Solve my issue by removing jest-cli from my package.json and did a |
This I feel should be included in the documentation. This solved so many mysterious bugs I got after upgrading Babel to 7 and |
@SethDavenport's fix (#7868 (comment)) worked for me. Using:
Without that patch, I still get the error: "TypeError: Cannot read property 'cwd' of undefined". And I'm using |
@maneetgoyal Could you please share your package.json? I've made the changes, but I still get the error. Thanks in advance! |
Also seeing this issue on "babel-jest": "24.9.0", "jest": "24.9.0", but only when running npm install, npm test. Yarn works. |
Whoever encounters this again: babel-jest and jest have to be the same version (Major). If an old project/service using @babel/plugin-transform-runtime
additionally: This Issue helped me All this happened when upgrading from babel 6.x to 7.x for me. I used this tool for that. |
I solved this issue by updating my Node version from 6.15 to 14.15.1 😅 |
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
I've updated one of my projects from babel 6 to babel 7. As part of this, I've also
When I run my tests, I get the following error:
I can "fix" this error and get my tests running again if I hack
node_modules/babel-jest/build/index.js
as follows:With this, my tests run fine, however I don't really understand under what circumstances
config
could be undefined.To Reproduce
Here are my configs:
package.json
:jest/js-loader.js
:Expected behavior
Tests to run as they did with babel 6/babel-jest 23.
Run
npx envinfo --preset jest
Paste the results here:
The text was updated successfully, but these errors were encountered: