[Bug?] Virtual paths cause duplicate module instantiation
See original GitHub issue- I’d be willing to implement a fix
Describe the bug
For Parcel , we have multiple modules that do this:
import {register} from "@parcel/core";
class X {}
register("X", X);
When installing Parcel via PnP, it seems like these modules are called multiple times (and register mustn’t be called multiple times - this works fine with Yarn 1).
I found out that the problematic file (@parcel/package-manager/lib/Npm.js
) is required & compiled via two different require chains, @parcel-package-manager-virtual-<TWO-DIFFERENT-IDS-HERE>
(see below).
I known this is problematic and somewhat relies on hoisting (and I already get some peerdependency warnings).
To Reproduce
😬
Example
Call chain 1
Trace: 2.0.0-alpha.3.2-dccf3d96:Npm
at registerSerializableClass (pnp/.yarn/unplugged/@parcel-core-npm-2.0.0-alpha.3.2-dccf3d96-27a2fe7d38/node_modules/@parcel/core/lib/serializer.js:27:13)
at Object.<anonymous> (pnp/.yarn/$$virtual/@parcel-package-manager-virtual-e6cacad87d/0/cache/@parcel-package-manager-npm-2.0.0-alpha.3.2-dccf3d96-3ccef4b8cf-2.zip/node_modules/@parcel/package-manager/lib/Npm.js:84:37)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.module_1.Module._load (pnp/.pnp.js:23984:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (pnp/.yarn/$$virtual/@parcel-package-manager-virtual-e6cacad87d/0/cache/@parcel-package-manager-npm-2.0.0-alpha.3.2-dccf3d96-3ccef4b8cf-2.zip/node_modules/@parcel/package-manager/lib/index.js:19:12)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
Call chain 2
Trace: 2.0.0-alpha.3.2-dccf3d96:Npm
at registerSerializableClass (pnp/.yarn/unplugged/@parcel-core-npm-2.0.0-alpha.3.2-dccf3d96-27a2fe7d38/node_modules/@parcel/core/lib/serializer.js:27:13)
at Object.<anonymous> (pnp/.yarn/$$virtual/@parcel-package-manager-virtual-939cfbf528/0/cache/@parcel-package-manager-npm-2.0.0-alpha.3.2-dccf3d96-3ccef4b8cf-2.zip/node_modules/@parcel/package-manager/lib/Npm.js:84:37)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.module_1.Module._load (pnp/.pnp.js:23984:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (pnp/.yarn/$$virtual/@parcel-package-manager-virtual-939cfbf528/0/cache/@parcel-package-manager-npm-2.0.0-alpha.3.2-dccf3d96-3ccef4b8cf-2.zip/node_modules/@parcel/package-manager/lib/index.js:19:12)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
Environment if relevant (please complete the following information):
- OS: macOS
- Node version: 12
- Yarn version: 2.0.0-rc.29
Additional context
Add any other context about the problem here.
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (13 by maintainers)
Top Results From Across the Web
java - Duplicate class in two modules in an application
It would only be duplicate if the FQN's were equal. If they are, the JVM will load the first one encountered by the...
Read more >cmd/go: no error reported for duplicate module paths ...
The go command does not return an error for duplicate module paths in a go.work file. Instead, it happily lets the last directory...
Read more >Errors and Warnings — Verilator 5.005 documentation
For some gate level netlists duplicates are sometimes unavoidable, and MODDUP should be disabled. Ignoring this warning will cause the more recent module...
Read more >Avoiding common confusions with modules in Angular
So a lazy-loaded module that imports that shared module makes its own copy of the service. So we know that Angular creates its...
Read more >Bug listing with status RESOLVED with resolution OBSOLETE ...
Bug :1523 - "[IDEA] Offload work by distributing trivial ebuild ... fails on any Gentoo virtual machine" status:RESOLVED resolution:OBSOLETE severity:normal ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yep, I still need to look into it, there’s a missing deduplication (cf my previous comment). Probably fixable on our side, will report back once I have more info 👍
Thanks for the fast response. I think the Parcel PnP PR is ready