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

Parcel 2 build failing with importScripts() is not supported in module workers. #6562

Closed
jessabyrne opened this issue Jul 7, 2021 · 2 comments · Fixed by #6582
Closed

Parcel 2 build failing with importScripts() is not supported in module workers. #6562

jessabyrne opened this issue Jul 7, 2021 · 2 comments · Fixed by #6582

Comments

@jessabyrne
Copy link

jessabyrne commented Jul 7, 2021

🐛 bug report

The build passes with parcel build public/index.html
but when I run parcel public/index.html I get the below error:

🚨 Build failed.

@parcel/transformer-js: importScripts() is not supported in module workers.

  /Users/jessabyrne/projectrepos/project/node_modules/@loaders.gl/loader-utils/dist/esm/lib/library-utils/library-utils.js:66:12
    65 | 
  > 66 |   return "modules/".concat(moduleName, "/src/libs/").concat(library);
  >    |            ^
    67 | }
    68 | 

It seems to get far along but fails near the end. I've tried clearing both the .cache and .parcel-cache as well as removing node_modules and reinstalling.

This happened after making some changes to fix other errors:

  1. changing <script async src="../src/index.tsx" type="text/javascript"></script> to <script async src="../src/index.tsx" type="module"></script>

    1. Changing
          navigator
            .serviceWorker
            .register('service-worker.js')

to

          navigator
            .serviceWorker
            .register(new URL('service-worker.js', meta.url))

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

package.json

    "@parcel/transformer-raw": "^2.0.0-nightly.755",
    "@parcel/transformer-typescript-tsc": "^2.0.0-nightly.755",
    "parcel": "^2.0.0-nightly.753",

.parcelrc

{
  "extends": "@parcel/config-default",
  "transformers": {
    "*.{ts,tsx}": ["@parcel/transformer-typescript-tsc"],
    "*.{jpg,png,svg}": ["@parcel/transformer-raw"]
  }
}

babel.config.json

{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react",
    "@babel/preset-typescript"
  ]
}

🤔 Expected Behavior

task should build

😯 Current Behavior

build fails

💁 Possible Solution

Could be related to this issue: #5021
also perhaps this PR #6531

🌍 Your Environment

Software Version(s)
Parcel 2.0.0-nightly.753
Node v16.3.0
npm/Yarn 7.15.1
Operating System osx Big Sur
@mischnic
Copy link
Member

mischnic commented Jul 7, 2021

This was an intentional change: #6536 (comment)

This comes from https://github.com/visgl/loaders.gl/blob/4323541bb8f0a5402e4ac28f8068e504c493dac7/modules/worker-utils/src/lib/library-utils/library-utils.ts#L86

We might have to only error if this is in user code and just ignore it in node_modules. @devongovett ?

@devongovett
Copy link
Member

That would result in broken code. Chrome will throw at runtime on importScripts inside module workers. Parcel is just raising the error at build time. That code should be replaced with a dynamic import() instead.

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

Successfully merging a pull request may close this issue.

3 participants