Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LukeTOBrien opened this issue Jul 15, 2022 · 7 comments

Comments

@LukeTOBrien
Copy link

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
Copy link
Author

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
Copy link

how to fix it?

@Kujo-Jotaro-AAAAA
Copy link

how to fix it?

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

@mevanloon
Copy link

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
Copy link
Author

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
Copy link
Author

@mischnic What do you think?

@github-actions github-actions bot added the Stale Inactive issues label Oct 17, 2023
@mischnic mischnic removed the Stale Inactive issues label Oct 17, 2023
@parcel-bundler parcel-bundler deleted a comment from github-actions bot Oct 17, 2023
@o0101
Copy link

o0101 commented Dec 26, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants