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.

How to import the module using Webpack?

See original GitHub issue

How do I import the module for use with a webpack dev server? Where do I put the magick.wasm and magick.js files? I’m using preact and start the dev server with preact watch. Can I edit webpack.config.js to include the files somehow?

edit: I’ve tried using copy-webpack-plugin, which seems to work if I build the project, but in the development server I get errors:

Uncaught (in promise) DOMException: Failed to register a ServiceWorker for scope ('https://localhost:8080/') with script ('https://localhost:8080/sw-debug.js'): An unknown error occurred when fetching the script.
DOMException: Failed to construct 'Worker': Script at 'webpack-internal:///../node_modules/wasm-imagemagick/dist/src/magick.js' cannot be accessed from origin 'https://localhost:8080'.
Uncaught (in promise) DOMException: Failed to construct 'Worker': Script at 'webpack-internal:///../node_modules/wasm-imagemagick/dist/src/magick.js' cannot be accessed from origin 'https://localhost:8080'.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

1reaction
fz6mcommented, Jan 14, 2022

I tried to modify the bundled output .js file, use a hack way of loading the Web worker in webpack.

image-magick

Unfortunately it takes a little longer to load the .js file (5 MB) for the first time in the page 😣

hope this helps

0reactions
orteth01commented, Nov 5, 2021

i have gotten this to work by including this script directly in my html

<script type="module">
  import * as Magick from 'https://knicknic.github.io/wasm-imagemagick/magickApi.js';
  window.magick = Magick;
</script>

as you can see, it imports the lib from a remote source and then puts it on the window object. I still include the wasm files in the public directory. I still include the node module in my dependencies so that I can grab the typescript types and use them to extend window.

it’s not ideal, but i also was not successful in any of my attempts to just use the npm module.

hope this helps!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module Methods - webpack
Version 2 of webpack supports ES6 module syntax natively, meaning you can use import and export without a tool like babel to handle...
Read more >
How to import bundle created in webpack? - Stack Overflow
My requirement is that this bundle.js will be put on a CDN so that I can use the modules exported in Project 1...
Read more >
Webpack and Dynamic Imports: Doing it Right - Medium
In Webpack normally we load images as modules using the file loader. The file loader will basically map the emitted file path inside...
Read more >
How to use an ES module and webpack - Educative.io
Step 1: Create a project directory · Step 2: Go to the project's root folder · Step 3: Create a package.json file ·...
Read more >
A Guide to Managing Webpack Dependencies - Toptal
The Webpack module bundler processes JavaScript code and all static assets, ... For this purpose, we can use require.ensure or System.import functions, ...
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