-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Symlink realpaths #1125
Comments
I just noticed something... for some reason |
@jamiebuilds when HMR is not enabled, we dedupe by file contents in the packager: parcel/src/packagers/JSPackager.js Lines 38 to 45 in f226d26
|
This is not quite right. Node’s
Resolving
Interestingly, since modules are cached based on the resolved file name, and That means that considering a file and a symlink of that file to be the same module while also resolving dependencies from symlinked paths would be a break away from Node, which is probably something we want to avoid, at least by default (tests behaving differently from bundles is not the best). If we do want to accommodate those unique scenarios I think it would make more sense as a non default Resolver that you can opt to plugin, which is something I’m hearing would be possible in Parcel@2. I do think it would good to enable people to use Node’s normal module resolution method though. @devongovett, maybe we should add an option for that? Also, just to put my personal opinion out there, I think it makes more sense to default to using Node’s normal resolution method. I think people might be surprised that Parcel is using |
Yeah, as much as resolution in every tool sucks right now. I think it's best to follow what others are doing and treat every minor deviation as a bug. With custom resolvers in Parcel 2 we can experiment with what a better model would be. If we figure out something significantly better. We can consider making it the default in the future. |
Is there any workaround for this? The only way to work with a local package that has peer deps is to sym link them in. But any package that has say React as a peer dep now gets many copies of React when using Parcel. Eg: In Webpack, I make an alias for all peer deps to force them to use Is there a workaround? |
Ahh. I see how the alias syntax works now. You need to be more explicit with the path. Module name alone does not resolve to root project's node_modules. You need to actually specify the absolute or relative-to-project path in the alias and then Parcel uses that for peer deps. So that's the work around for me. |
Parcel's deviation from the I've since been debugging Parcel's custom module resolution strategy and can see the problem. It's not using the real path so it cannot find the transitive dependencies which are located relative to the direct dependency (following the link). |
This might be the root cause for #1838 ? |
Until #2946 is merged, pnpm users can use the --shamefully-flatten option of pnpm. |
@devongovett - Can we get this PR merged please? Using parcel-bundler with PNPM is currently not possible unless we use the |
@sadsa This is not a pull request, and it's not a simple problem. |
This should be closed since #3471 or only after official v2 release? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. |
Currently, (as of 1.7) if you have a project that looks like this:
index.js
require('./target');
require('./symlink')
target.js
...
symlink.js
./target.js
)The contents and dependencies of
target.js
will be duplicated.This is because Parcel does not
fs.realpath
file paths as they are resolved, and for good reason: If you have anpm link
-d package in yournode_modules
and youfs.realpath
it before resolving its dependencies, then you can get multiple copies of the same dependencies. Basically, Parcel is following Node's--preserve-symlinks
option.Dependency resolution should continue to work this way, but before we add a module to the graph, we should then
fs.realpath
it and if it already exists we should not re-add it. This also matches Node's behaviour because symlinked modules do not get re-evaluated in Node, where right now they do (in effect) in Parcel.We should:
fs.realpath
on modules before we add them to the graph and avoid them ending up in our bundles multiple times.The text was updated successfully, but these errors were encountered: