Open RichardJECooke opened 1 year ago
And here's the generated JS code, which looks roughly right to me, at least serviceWorker.js
has the right name.
(parcelRequire("2JpsI")).register(JSON.parse('{"cpKN1":"index.5375eb8a.js","exyRE":"serviceWorker.js"}'));
...
var $8308987b7f2d1c72$exports = {};
$8308987b7f2d1c72$exports = new URL((parcelRequire("2JpsI")).resolve("exyRE"), import.meta.url).toString();
async function $db13d2c0f4fb9b17$var$registerServiceWorker() {
if ("serviceWorker" in navigator) try {
const registration = await navigator.serviceWorker.register($8308987b7f2d1c72$exports, {
scope: "/"
});
If I put $8308987b7f2d1c72$exports = new URL((parcelRequire("2JpsI")).resolve("exyRE"), "http://journal.example.app").toString();
in the console it gives me the right filename.
My ts.config
of my root folder is
{
"extends": "@vue/tsconfig/tsconfig.web.json",
"include":
[
"env.d.ts", "src/**/*", "src/**/*.vue"
,"src/external/dropbox/dropbox_sdk_10_32_0.js"
],
"compilerOptions":
{
"alwaysStrict": true,
"baseUrl": ".",
"importsNotUsedAsValues": "remove",
"isolatedModules": false,
"lib": ["ES2021", "DOM", "webworker"],
"module": "ES2020",
"moduleResolution": "node",
"noImplicitAny": true,
"paths": { "@/*": ["./src/*"] },
"preserveConstEnums": true,
"preserveValueImports": false,
"removeComments": true,
"sourceMap": true,
"strict": true,
"strictNullChecks": true,
"target": "ES2021",
"types": ["node", "dropbox"]
},
}
navigator.serviceWorker.register(new URL('./serviceWorker.ts', import.meta.url), {type: 'module', scope: '/' })
That is definitely the version you should be using. If you put the url constructor outside, then Parcel doesn't know that serverWorker.ts
should be the service worker.
Not sure yet why that then fails to load the correct url
Thanks @mischnic. Here's a reproducible example: https://we.tl/t-6RVGridxhJ
Run:
npm update
npm run dev # browse to localhost:1234 and see that it works
npm run preview # browse to localhost:1234 and see that it doesn't work
I can confirm this issue.
Uncaught (in promise) DOMException: Failed to register a ServiceWorker for scope ('https://test.local/') with script ('https://test.local/undefined')
Parcel tries to load an undefined URL. My service worker URL should be https://test.local/service_worker.js.
Interestingly, if I pass the --no-scope-hoist
flag when building, then Parcel loads the correct URL.
I have this problem with 2.12.0. Has no progress really been made in over a year? This is a show-stopping bug.
Is the value of import.meta.url really meant to be file:///src/index.ts
even when serving from a web server?
🐛 bug report
My PWA works fine when using the Parcel dev server on my localhost. So I tried building and deploying to a webhost and it breaks.
When using the build command
parcel build --no-content-hash --no-source-maps --no-optimize src/index.html
, and copying the output to a serverI get the error
caught (in promise) TypeError: Failed to construct 'URL': Invalid URL at $db13d2c0f4fb9b17$var$registerServiceWorker (index.5375eb8a.js:66710:30)
.Here's the code that gives the error (taken from
https://parceljs.org/languages/javascript/#service-workers
)I can't debug this because I can't see what URL Parcel is trying to generate here.
If I don't try to put the URL in a string, like this:
and build, Parcel now doesn't add a hash to the service worker filename
and I get a different error when browsing to the site:
🎛 Configuration (.babelrc, package.json, cli command)
package.json
🤔 Expected Behavior
The service worker should load and I should be able to log its path to the console. The service worker filename should not be given a hash no matter what code calls it.
😯 Current Behavior
Parcel's path assignment for the service worker is broken. Parcel keeps changing the service worker filename.
🌍 Your Environment