question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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:closed
  • Created 4 years ago
  • Comments:15 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
arcaniscommented, Mar 9, 2020

but @parcel/package-manager is still duplicated…

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 👍

0reactions
mischniccommented, Mar 9, 2020

Thanks for the fast response. I think the Parcel PnP PR is ready

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found