parcel-bundler / parcel

The zero configuration build tool for the web. πŸ“¦πŸš€
https://parceljs.org
MIT License
43.41k stars 2.26k forks source link

Error: Registering service workers with a string literal is not supported. - Importing jquery #8307

Closed LukeTOBrien closed 2 months ago

LukeTOBrien commented 2 years ago

Hello

I am getting the following error whilst importing jQuery and assigning it to a variable:

@parcel/transformer-js: Registering service workers with a string literal is not supported.

  C:\VB Azure\EntERPro\UI\ASP\static\Script\script.ts:16:38
    15 |
  > 16 | window['$'] = window['jQuery'] = jquery
  >    |                                      ^^^
    17 | window['functions'] = Functions;
    18 |

  πŸ’‘ Replace with: new URL('service-worker.js', import.meta.url)
  πŸ“ Learn more: https://parceljs.org/languages/javascript/#service-workers

My script is:

import jquery from 'jquery';

...

window['$'] = window['jQuery'] = jquery

πŸ€” Expected Behavior

I should be able to import jQuery and assign it to a global variable.
The error message shouldn't mention service workers when they are not being used

🌍 Your Environment

Software Version(s)
Parcel 2.6.2
Node v16.16.0
npm 8.11.0
Operating System Windows 10
{
    "@parcel/transformer-typescript-tsc": "^2.6.2",
    "parcel": "^2.6.2",
}
LukeTOBrien commented 2 years ago

I have just cloned my project onto a new machine and updated Parcel the 2.6.2 from 2.0.0-rc.
Here is my tsconfig, perhaps I need to update that also?

{
    "compilerOptions": {
        "module": "commonjs",
        "noImplicitAny": false,
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": true,
        "esModuleInterop": true,
        "target": "es2019"
    }
}
Kujo-Jotaro-AAAAA commented 1 year ago

how to fix it?

Kujo-Jotaro-AAAAA commented 1 year ago

how to fix it?

I got this issue @parcel/transformer-js: Registering service workers with a string literal is not supported.

mevanloon commented 1 year ago

I worked around this by putting the serviceWorker object in a separate reference:

const s = navigator.serviceWorker
s.register('worker.js')

This tricks Parcel, but it works for me (for now). There are probably some issues down the line with this.

LukeTOBrien commented 1 year ago

I am not using service workers at all, I am just importing jQuery.

I think I remember 'solving' this issue by reverting back to ParcelJS 2-beta... Now I made the mistake of updating to 2.8 and I see this issue is still present.
This error is wrong and is causing the build to fail.

🚨 Build failed.

@parcel/transformer-js: Registering service workers with a string literal is not supported.

  C:\VB Azure\EntERPro\UI\ASP\static\Script\scripts-main.ts:21:38
    20 | window['$'] = window['jQuery'] = jquery;
  > 21 | window['functions'] = Functions;
  >    |                                 ^
    22 |
    23 | VhFix();

  πŸ’‘ Replace with: new URL('service-worker.js', import.meta.url)
  πŸ“ Learn more: https://parceljs.org/languages/javascript/#service-workers
LukeTOBrien commented 1 year ago

@mischnic What do you think?

o0101 commented 9 months ago

Also seeing this on windows. Going to try the hacky workaround!

github-actions[bot] commented 3 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.