rollup-plugin-comlink icon indicating copy to clipboard operation
rollup-plugin-comlink copied to clipboard

Cannot find module .../worker.js?comlink

Open danvratil opened this issue 4 years ago • 0 comments

Hi,

I'm trying to get this plugin to work following the minimal example from the README, but I'm getting a Cannot find module error.

rollup.config.js

import comlink from "@surma/rollup-plugin-comlink";
import omt from "@surma/rollup-plugin-off-main-thread";

export default {
  input: ["src/main.js"],
  output: {
    dir: "dist",
    format: "amd",
  },
  external: ['comlink'], <--- I added this one to fix a warning
  plugins: [comlink(), omt()],
};

src/main.js

import workerAPI from "comlink:./worker.js";

(async function () {
  const result = await workerAPI.doMath(40, 2);
  console.assert(result == 42);
})();

src/worker.js

export function doMath(a, b) {
  return a + b;
}

package.json

{
  "name": "proj",
  "version": "1.0.0",
  "main": "index.js",
  "dependencies": {
    "@surma/rollup-plugin-comlink": "^0.4.0",
    "@surma/rollup-plugin-off-main-thread": "^2.2.3",
    "comlink": "^4.3.1"
  },
  "devDependencies": {
    "rollup": "^2.64.0",
  }
}

However it doesn't build:

$ rollup -c rollup.config.js
src/main.js → dist...
[!] (plugin off-main-thread) Error: Cannot find module '/tmp/proj/src/worker.js?comlink' from 'comlink:/tmp/proj/src/worker.js'
Error: Cannot find module '/tmp/proj/src/worker.js?comlink' from 'comlink:/tmp/proj/src/worker.js'
    at Object.resolveId (/tmp/proj/node_modules/@surma/rollup-plugin-off-main-thread/index.js:85:15)
    at async resolveId (/tmp/proj/node_modules/rollup/dist/shared/rollup.js:21755:26)
    at async ModuleLoader.resolveId (/data/proj/node_modules/rollup/dist/shared/rollup.js:22059:19)
    at async /tmp/proj/node_modules/rollup/dist/shared/rollup.js:22353:42

Am I missing something in rollup config, or doing something wrong?

danvratil avatar Jan 20 '22 21:01 danvratil