New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
default export doesn't work. "TypeError: xxx is not a function" #54
Comments
Yes your right will fix the code |
Released a fix as 3.0.1. Thanks for the report! |
Still doesn't work. If importing the default export, I get the following error:
|
Are you sure you are on the latest version? |
|
It works properly see https://github.com/mathe42/comlink-test please change to "3.0.2" and not "^3.0.2". I need a full reproduction to fix that. |
Here's my repro:
|
I could reproduce that but have no idea why. I will investigate please use |
I have no idea why it works with my project and not yours. I published a new version 3.0.3 that didn't fix it. I will keep looking into it but not today. |
I have NO idea why it worked for me... I will change the readme for now until I find a solution... |
Normally, you just have to change export function To export default function Right? I can't explain the local reproduction issue, though. |
It's the Seems that something is broken with the .mjs module, but this looks fine. var src_default = comlink;
export {
comlink,
src_default as default
}; |
It uses the normal .js file in both cases. but I think you are right that this is the problem I'm not sure why node uses the default import the same as |
It does, but it should be using the .mjs I think. I can't get it to load the mjs file. I've tried adding |
note that this might be a combination with vite problem as at vite startup the config file is compiled to JS (and I think the complete config is bundled to a single file internaly.) The output of that is interpreted as a commonjs (or with type=module a esm)-File. |
What is the reason you want to set |
I have it as it's kinda the new standard, not much else. I also had some errors with https://github.com/liuweiGL/vite-plugin-mkcert which I fixed by calling Could this be related to vitejs/vite#6623? I also noticed that when compiling in lib mode in Vite, they recommend using the following package.json: {
"name": "my-lib",
"files": ["dist"],
"main": "./dist/my-lib.umd.js",
"module": "./dist/my-lib.es.js",
"exports": {
".": {
"import": "./dist/my-lib.es.js",
"require": "./dist/my-lib.umd.js"
}
}
} Compared to yours it's missing the |
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. |
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: So there is no harm in waiting for v4 as it will have a number of breaking changes. |
First off, thank you for making this!
I noticed in the installation section, your
vite.config.js
reads:In practice, I'm only able to get it to work with:
Is this the intended behaviour?
The text was updated successfully, but these errors were encountered: