vite-plugin-comlink: default export doesn't work. "TypeError: xxx is not a function"

First off, thank you for making this!

I noticed in the installation section, your vite.config.js reads:

import comlink from 'vite-plugin-comlink'

In practice, I’m only able to get it to work with:

import { comlink } from 'vite-plugin-comlink'

Is this the intended behaviour?

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 1
  • Comments: 19 (12 by maintainers)

Most upvoted comments

I know that vite 3 is out but I’m currently quite busy (I’m in my last year of University) so at least in the next 4-5 Weeks don’t expect a fix. I didn’t even had a look at vite 3 yet. (so also vite-plugin-comlink version 4 is pushed back). On npmjs I can see that a lot of persons only use an old version:

image

So there is no harm in waiting for v4 as it will have a number of breaking changes.

Might be. exports field doesn’t change anything. Reproduction is still broken. I think the best solution is to avoid the default import. vite 3 will have some changes with esm files etc. so I would not touch it for now and wait for the 3.0 release.

It’s the "type": "module" in the project’s package.json which breaks it. This instructs the project to use esm module resolution with node 16+

Seems that something is broken with the .mjs module, but this looks fine.

var src_default = comlink;
export {
  comlink,
  src_default as default
};

Yes your right will fix the code