-
-
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
Jest ignoring browser field in package.json of a module dependency sub-directory #4756
Comments
Update... I may have jumped the gun. It seems Jest is using a third party module for browser-resolution. I think it may be the one not handling this use-case. I'll leave the ticket up for now as I investigate further, but others may run into this same issue. Not sure what the stance is on bugs related to third party modules that are used by Jest. |
Can you create a small repro repo? I use marko at work myself, but only on the server-side, so I haven't hit this case before.
There is no file called |
That doesn't sound right either, jest uses EDIT: Ah, for the browser-part specifically https://github.com/defunctzombie/node-browser-resolve That's what browserify uses as well |
Jest-resolve uses So, I'm not entriely sure who should be the one to address this, on one hand Jest could normalize the basedir to the directory location of the actual file (accounting for relative paths) or you could say that the |
Actually, the more I look at this the more I think it needs to be resolved on the |
So it seems there are a couple of issues at play.
In the end, the only way I have managed to get this resolved is to create my own resolver which basically just mimics what
Obviously, this is not very efficient to have to resolve the path twice, so for now I've limited the second pass to only paths which match the |
Since this issue was made a new marko jest transform and preset was released. This preset overrides the resolver to side step this issue and instead uses enhanced-resolve-jest. Would be good to rip out the |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days. |
This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
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
What is the current behavior?
I'm using a package called Markojs, this package makes heavy use of the "browser" field in package.json - not just at the root, but throughout the module src hierarchy. Jest does not abide by these file remaps in sub directories, causing errors when trying to test Marko components with Jest. Everything works fine in Node, as the resolver is able to properly resolve the remapped files.
I am setting the "browser" flag on Jest to true, and it appears to be carrying through the proper code execution in Jest. But, I believe the issue is that the
sync.js
file in Jest, on line 24, first tries to load the file as afile
, which passes, so theloadAsDirectorySync
function never fires, and that appears to be the only place where the package.json browser file remap is checked. Since it's a file in a sub directory, and the file does exists (however is not the correct one) the browser package logic is never checked in that directory.For more details, the first file that I am encountering such a failure on is in the https://github.com/marko-js/marko/tree/master/src/components directory on the utils.js file, which as you can see in that directories package.json file should be remapped to the utils-browser.js file.
What is the expected behavior?
Files should be resolved to the files specified in the browser field, regardless of where the package.json lives
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
Jest
20.0.4
Node
v8.6.0
Yarn
1.1.0
The text was updated successfully, but these errors were encountered: