rollup-plugin-comlink
rollup-plugin-comlink copied to clipboard
TypeScript: (plugin comlink) TypeError: Cannot read property 'id' of null
Followed Readme instruction, cannot compile with error:
[!] (plugin comlink) TypeError: Cannot read property 'id' of null TypeError: Cannot read property 'id' of null at Object.resolveId (D:\sourcecode\frontend\ts-rollup-web-worker\node_modules\@surma\rollup-plugin-comlink\index.js:55:58)
base code was from rollup-starter-lib typescript
branch.
rollup.config.js
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import typescript from 'rollup-plugin-typescript';
import comlink from "@surma/rollup-plugin-comlink";
import omt from "@surma/rollup-plugin-off-main-thread";
import pkg from './package.json';
export default [
// browser-friendly UMD build
{
input: 'src/main.ts',
output: {
name: 'howLongUntilLunch',
file: pkg.browser,
format: 'amd'
},
plugins: [
comlink(),
omt(),
resolve(), // so Rollup can find `ms`
commonjs(), // so Rollup can convert `ms` to an ES module
typescript() // so Rollup can convert TypeScript to JavaScript
]
},
// CommonJS (for Node) and ES module (for bundlers) build.
// (We could have three entries in the configuration array
// instead of two, but it's quicker to generate multiple
// builds from a single configuration where possible, using
// an array for the `output` option, where we can specify
// `file` and `format` for each target)
// {
// input: 'src/main.ts',
// external: ['ms'],
// plugins: [
// typescript() // so Rollup can convert TypeScript to JavaScript
// ],
// output: [
// { file: pkg.main, format: 'cjs' },
// { file: pkg.module, format: 'es' }
// ]
// }
];
Hi @navono,
you need to import your worker and specify .ts
extension like so: import workerAPI from "comlink:./worker/worker.ts";
@navono Can you give me some reproduction steps? There’s all kinds of dependencies and other cruft, the tests don’t pass and I honestly have no idea how to reproduce the error you are complaining about.
(You are definitely importing a wrong/non-existent file here)
first all, I have done with readme instruction about typescript.
// main.ts
import workerAPI from "comlink:./worker.js";
console.log(await workerAPI.sayHello("surma"));
// This would fail to compile:
// console.log(await workerAPI.doesNotExit("surma"));
// worker.ts
export function sayHello(name: string): string {
return `Hello ${name}!`;
}
// worker-modules.d.ts
declare module "comlink:./worker.js" {
// Do *not* move this to a top-level import, as it will turn this
// .d.ts file from an ambient module into a local module.
const wrap: import("comlink").Remote<typeof import("./worker.js")>;
export default wrap;
}
no lucky.
then as @boazhoch said, I change .js
to .ts
as you can see in comlink
branch code, also not work.
Steps to reproduce
- clone this repo
- checkou out
comlink
branch - enter
rollup-lib
directory - executen
yarn
, thenyarn build
.
Hope I explained the steps clearly.