Giter Site home page Giter Site logo

Comments (2)

mkamalkayani avatar mkamalkayani commented on June 11, 2024

I am also getting exactly same error. I am using nextjs 12 with default webpack config. I also tried

const worker = new Worker(new URL("./test.worker.js", import.meta.url), { type: 'module' }); but it also did't work.

Tested it on:
Chrome: 96.0.4664.93 (Official Build) (x86_64)
Firefox: 95.0 (64-bit)

@dandansoysauce would you kindly share your solution.

from worker-plugin.

antoniocaiazzo avatar antoniocaiazzo commented on June 11, 2024

A bit late for my reply, and also not much of a solution, but I've found that the only way for web Workers to actually work in Next.js and Webpack is to respect as closely as possible this example: https://github.com/vercel/next.js/tree/canary/examples/with-web-worker (the .babelrc file is not necessary).

Admittedly I don't know the reasons behind it (still starting out with Next.js and Webpack).

If for example you store import.meta.url in a variable you get an opaque error like:

Security Error: Content at http://localhost:3000/ may not load data from file:///...../with-web-worker-app/worker.js.

Which happened during some tests and took some time to track down. And also if you try to create the Worker object in a separate function (say for a factory pattern) passing in the URL object as a parameter, you get another unrelated error:

SyntaxError: import declarations may only appear at top level of a module

Waiting for someone with more experience to shed some light on this.

from worker-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.