-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Resolve symlinks using Node resolution mechanism #3883
Comments
I think the correct fix would be to:
|
Even more interesting. Apparently Jest itself doesn't quite use Node module resolution. In fact I was the one who changed Jest from It seems like maybe we should support both? I believe webpack has a flag for it. Maybe Jest could have a flag too. |
While this is fresh in my mind, I immortalized this dilemma in a tweet. Hope this is helpful to whoever ends up reading this to consider fixes (me?) |
Filed an issue in Jest. |
@bradfordlemley Do you have thoughts on this? You probably spent more thinking about symlinks than most of us :-) |
After more digging, the reason "jest already worked correctly" in #1359 per #1359 (comment) was because Jest was not respecting Node resolution. Since I fixed Jest in jestjs/jest#4761, that integration has regressed. But again, it was broken in the first place because it didn't match how Node resolves modules. |
Is it somehow related to #3547? |
I found a workaround that I use in my projects. You can run a watch process to compile your shared library and use it as symlink in your project. Here is my gist. |
Any progress on this? I'm game to help if there's work to be done. |
Any progress or a workaround for this that doesn't require running a watcher compiler? |
Any progress on this? |
Is there a scenario where someone would prefer having dependencies read from linked node_modules instead from CRA-based project's node_modules? Modifying If there is no scenario, then maybe CRA should have the value, from above, hardcoded? |
I just encountered this and after many many attempts to get around it, I ended up installing // .rescriptsrc.js
const path = require('path')
const resolveFrom = require('resolve-from')
module.exports = [
config => {
config.resolve = {
...config.resolve,
alias: {
...config.resolve.alias,
react$: resolveFrom(path.resolve('node_modules'), 'react'),
'react-dom$': resolveFrom(path.resolve('node_modules'), 'react-dom')
}
}
return config
}
] Leaving here for posterity. |
Up |
I believe #7993 will fix this. |
Over at Vim we've arrived at a decent working solution using craco. |
Copying my comment from #1107 since that issue is pretty crowded and I want it to be here instead.
Having read some discussions in nodejs/node#6537 and https://github.com/isaacs/node6-module-system-change I think we're actually already being inconsistent in how we handle symlinks.
Let's forget about the issue about compiling source code for a second. I feel like that can be solved by #1333 and thus is not the most important one here.
The important part here is that the resolution should match Node algorithm so that our webpack setup matches our test setup. I thought that was the case, but I was wrong.
Consider this structure:
It turns out that if
my-comp
doesn't declare a dependency onreact
, it can find React in the browser builds but not in tests.We introduced this regression in #1359.
We probably missed it because if
my-comp
does explicitly depend on React (e.g. as adevDependency
), the test passes (and in the browser we just get two Reacts).The text was updated successfully, but these errors were encountered: