-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Error: Cannot find module './package' from 'index.js' #286
Comments
What version of enzyme? Can you include a sample of how you're importing |
my enzyme version is 2.2.0 this is how i import shallow
this is the stack trace for the error
I have now added json to the moduleFileExtensions config for jest in my project which resolves the issue. I have submitted a pr to change the docs accordingly. |
ah ok, so it's specific to jest mocking. thanks for clarifying |
This is not specific to Jest. It is related to cheerio. In my case it was happening with karma configured using webpack. I provided a workaround here: cheeriojs/cheerio#836 |
Hmm - that seems like an issue with webpack then. implicit |
It might be a little more complicated than that. I left out some details in my response. I had webpack configured to resolve to a source folder as follows:
It looked to me like because cheerio was doing Yes, the |
With @goivemaster's fix my colleague is seeing this issue intermittently unless they run jest with the The error I see is:
Failure moves around tests intermittently as mentioned unless tests are run in a single thread ( The plot thickens - on my machine I see intermittent failures without the The it("should render the dashboard links", () => {
const appControls = shallow(<AppControls />);
expect(appControls.find('.app-control-link').length).toBe(2);
}); producing:
and: it("sets normal image src", () => {
const loading = shallow(<Loading />);
const loadingImg = loading.find("img");
expect(loadingImg.node.props.src).toBe(PathHelpers.LOADING);
}); resulting in:
|
FYI I think it must have been a fluke that this worked with I see that we are not the only ones having this issue, #309 looks to be related |
I can replicate this issue with Jest and React Native. |
What version of jest?
|
@blainekasten Version 13 (the newest one). "enzyme": "^2.3.0"
|
Are you also using the |
@blainekasten I tried both using |
If you add "jest": {
"moduleFileExtensions": [
"js",
"json"
]
} |
@aj0strow Thanks, that worked perfectly! |
Thanks @aj0strow! I'm closing this as it seems resolved, and it's not actually an enzyme issue, so nothing actionable for us. |
I know this is closed, but it seems that if setting the "moduleFileExtensions" property without adding "json" causes an issue, then this is an issue with Jest, if it causes an issue in the execution of one of its dependencies. Enzyme is using Cheerio Here's their changlog: https://github.com/cheeriojs/cheerio/blob/master/History.md |
This is definitely a webpack and/or jest bug. |
Trying to get the tests running. See this thread: enzymejs/enzyme#286 (comment)
I know this post is closed, but I'd like to share the silly solution that solved my issue. The problem in my case was someone was importing the component from the HOC ( Therefore the solution was to import the component from the exported component and not the HOC or connected component. |
@nickkhall that's not actually the right solution :-) you want |
getting this error when trying to import shallow from enzyme in test component for the first time.
The text was updated successfully, but these errors were encountered: