parcel-bundler / parcel

The zero configuration build tool for the web. 📦🚀
https://parceljs.org
MIT License
43.41k stars 2.26k forks source link

Web Workers module resolution #5223

Closed arb000r closed 3 years ago

arb000r commented 3 years ago

🐛 bug report

Hi all,

Been working with the Parcel 2 beta for my latest project and noticed some weird behaviour when working with web workers.

The short of it is, if a module is being used in a web worker -> and then that same module is being used outside the web worker, Parcel fails to resolve that module with an all too familiar.

index.793d37d4.js:58 Uncaught Error: Cannot find module '2MjDa'

I've attached a recreation repository.

🎛 Configuration (.babelrc, package.json, cli command)

{
    "name": "balancer-visualiser",
    "author": "Ansaf Ahmed <contact@ansaf.me>",
    "version": "1.0.0",
    "scripts": {
        "dev": "parcel ./src/index.html",
        "build": "parcel build --no-scope-hoist ./src/index.html"
    },
    "dependencies": {
        "@iconscout/react-unicons-solid": "^0.0.2",
        "@popperjs/core": "^2.5.2",
        "@tippyjs/react": "^4.1.0",
        "@types/": "iconscout/react-unicons-solid",
        "@types/bent": "^7.3.0",
        "@types/echarts": "^4.6.5",
        "@types/lodash": "^4.14.157",
        "@types/numeral": "^0.0.28",
        "@types/paralleljs": "^0.0.20",
        "@types/react": "^16.9.43",
        "@types/react-dom": "^16.9.8",
        "@types/styled-components": "^5.1.3",
        "@types/styled-system": "^5.1.10",
        "babel-plugin-styled-components": "^1.11.1",
        "bent": "^7.3.10",
        "date-fns": "^2.16.1",
        "echarts": "^4.9.0",
        "framer-motion": "^2.6.6",
        "graphql-combine-query": "^1.2.2",
        "graphql-tag": "^2.11.0",
        "lodash": "^4.17.19",
        "numeral": "^2.0.6",
        "paralleljs": "^1.1.0",
        "parcel": "^2.0.0-nightly.385",
        "react": "^16.13.1",
        "react-content-loader": "^5.1.2",
        "react-dom": "^16.13.1",
        "react-popper": "^2.2.3",
        "react-query": "^2.12.1",
        "react-router5": "^8.0.1",
        "regenerator-runtime": "^0.13.7",
        "router5": "^8.0.1",
        "router5-plugin-browser": "^8.0.1",
        "router5-plugin-logger": "^8.0.1",
        "rxjs": "^6.6.3",
        "styled-components": "^5.1.1",
        "threads": "^1.6.3",
        "tiny-worker": "^2.3.0",
        "typescript": "^3.9.7"
    },
    "devDependencies": {
        "@parcel/transformer-svg-react": "^2.0.0-nightly.1739",
        "@parcel/transformer-svgo": "^2.0.0-nightly.1739",
        "@parcel/transformer-typescript-tsc": "^2.0.0-beta.1",
        "@parcel/validator-typescript": "^2.0.0-beta.1",
        "graphql": "^15.3.0",
        "graphql-import-macro": "^1.0.0"
    }
}

🤔 Expected Behavior

Should not break the application when a module is used in a web worker and outside a web worker.

😯 Current Behavior

Application breaks when module is used in web worker and also outside.

💁 Possible Solution

🔦 Context

💻 Code Sample

Branch used: feature/Final-Phase-1 Repository: https://github.com/1saf/balancer-visualiser Error reproduction: In console. Code files to look at: batchquerybuilder.ts (the web worker), graphql.ts line 22 (where worker is spawned) Steps to re-create: Uncomment the bug recreation comments in either file.

index.793d37d4.js:58 Uncaught Error: Cannot find module '2MjDa'
    at newRequire (index.793d37d4.js:58)
    at newRequire (index.793d37d4.js:42)
    at localRequire (index.793d37d4.js:80)
    at Object.13C6p.react (AppLayout.tsx:3)
    at newRequire (index.793d37d4.js:68)
    at localRequire (index.793d37d4.js:80)
    at Object.2Wi3i.react (App.tsx:3)
    at newRequire (index.793d37d4.js:68)
    at localRequire (index.793d37d4.js:80)
    at Object.65wUL.react (main.tsx:5)

🌍 Your Environment

Software Version(s)
Parcel 2 Nightly
Node 12.12.0
npm/Yarn 1.22.4
Operating System WSL Ubuntu
arb000r commented 3 years ago

Just tested with latest nightly. Is fixed, my bad.

cfoust commented 3 years ago

This is still happening for us even on the latest nightly

mischnic commented 3 years ago

@cfoust Could you provide a reproduction in a new issue?

cfoust commented 3 years ago

Will do when I get a moment, thanks!