parcel-bundler / parcel

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

Unable to add workbox-precaching to service worker #9922

Open fluffyball9 opened 3 months ago

fluffyball9 commented 3 months ago

🐛 bug report

Attempting to import {precacheAndRoute} from 'npm:workbox-precaching' in my service worker results in this error:

@parcel/core: Failed to resolve 'd87982a6ed0e5ad6:./index.js:esm' from '.../node_modules/workbox-precaching/index.mjs'

  .../node_modules/workbox-precaching/index.mjs:1:8
  > 1 | export * from './index.js';
  >   |        ^^^^^^^^^^^^^^^^^^^^^

@parcel/resolver-default: Unknown url scheme or pipeline 'd87982a6ed0e5ad6:'

with ... being an absolute path to node_modules (not in default location as glitch symlinks node_modules to a different location)

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

.parcelrc

{
  "extends": "@parcel/config-default",
  "namers": ["./parcelNamer.js"],
  "transformers": {
    "*.js": ["./parcelTransformer.js", "..."]
  },
  "compressors": {
    "*.*": [
      "...",
      "@parcel/compressor-gzip",
      "@parcel/compressor-brotli"
    ]
  }
}

package.json targets

"targets": {
  "default": {
    "sourceMap": false,
    "outputFormat": "global",
    "context": "browser"
  }
}

🤔 Expected Behavior

Parcel should be able to include workbox without throwing an error

😯 Current Behavior

@parcel/core: Failed to resolve 'd87982a6ed0e5ad6:./index.js:esm' from '.../node_modules/workbox-precaching/index.mjs'

  .../node_modules/workbox-precaching/index.mjs:1:8
  > 1 | export * from './index.js';
  >   |        ^^^^^^^^^^^^^^^^^^^^^

@parcel/resolver-default: Unknown url scheme or pipeline 'd87982a6ed0e5ad6:'

💁 Possible Solution

idk

🔦 Context

Trying to include workbox-precaching in service worker

💻 Code Sample

Sample service worker

import {precacheAndRoute} from 'npm:workbox-precaching';
precacheAndRoute(self.__WB_MANIFEST);

imported using navigator.serviceWorker.register(new URL("sw.js", import.meta.url), {type: 'module'});

🌍 Your Environment

Software Version(s)
Parcel 2.12.0
Node 16.14.2
npm 7.20.6
Operating System Ubuntu 16.04

Using glitch.com if that helps

fluffyball9 commented 2 months ago

My guess now is that it has something to do with node_modules being a symlink to a different directory as this works fine locally on my windows computer