question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Worker not bundling imported files

See original GitHub issue

I am trying to load a Worker in the following way:

const url = new URL('./path/to/worker.ts', import.meta.url);
const worker = new Worker(url);

In the worker file I am trying to do an import:

import { someFunction } from './functions';

someFunction();

If I don’t provide { type: 'module' } to the Worker constructor, the import doesn’t get bundled with the worker and the following error is displayed in the console:

Uncaught SyntaxError: Cannot use import statement outside a module

If I do provide { type: 'module' } to the Worker constructor then it request the file without the extension: http://localhost:8080/functions which then returns a 404 due to the fact that a file without the extension doesn’t exist.

I would expect this to be bundled similar to the way that it is bundled when creating a webpage that uses imports as well where everything is in one file. Is there something I am doing wrong or is this a missing Webpack feature?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:18 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
alexander-akaitcommented, Jul 13, 2022

@debo07 don’t worry, it is in my TODO list, sorry for delay, a lot of tasks

0reactions
webpack-botcommented, Nov 12, 2022

Issue was closed because of inactivity.

If you think this is still a valid issue, please file a new issue with additional information.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Workers not bundling imported files for node environments
If the workers are not in the entry files they won't be bundled properly and the worker imports don't get bundled or chunked....
Read more >
Bundling · Cloudflare Workers docs
Files which will not be bundled. Bundling your Worker code takes multiple modules and bundles them into one. Sometimes, you might have ...
Read more >
How to configure webpack 5 to bundle the module Web ...
It works fine if there are no imports used in the script. But when I import any node modules (e.g. loadash/get ) or...
Read more >
How to bundle WebWorker coded with TypeScript in npm ...
The main code of the npm package imports and calls the WebWorker file. ... Without this, it will not bundle them into a...
Read more >
Module Methods - webpack
File extensions are required when importing wasm file ... Inline comments to make features work. ... Any module that matches will not be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found