-
-
Notifications
You must be signed in to change notification settings - Fork 45
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
unable to use server on node.js #20
Comments
Good point... I used full/partial imports in other projects, both server and client side, and since it worked out of the box I assumed it would work for other vanilla projects too ...but apparently not, thanks for noticing/reporting it with the clear minimal example. I guess it has something to do with how it is bundled and how module resolution works. It's more difficult than I though to make make it compatible with browser/typescript/node/ all at once ...somehow they all import slightly differently. Dammit. |
I fear I have to split it into different builts :/ |
Now I can find the root cause and work around In node.js, javascript type=module, from
change to
and many other files in dist/esm too |
I noticed that too... I'd have to change the sources though and verify it doesn't break for typescript/vite/cloudflare workers since I use these "in production" for https://passwordless.id |
Can confirm with change of exports to .js that importing |
I already have the problem that the jest tests fail when importing with ".js" extensions:
|
To sum it up...
It's funny how the js ecosystem is "destandardized", or I'm missing something. Every lib I look at seems to do things slightly differently so I don't know the "right way" to do it. As far as I could see, imports without file extension seem more widespread... And feels more natural to me. It feels weird to write "import ...js" to actually import a "ts" file. Checklist for a successful change, it should at least work with:
Perhaps instead of changing file extensions, it may make sense to split it into separate client and server builts, each minified and bundled... But I think it might negatively affect the size of imported code for partial imports. |
Yeah, it's quite a bit to work through. Also keep in mind that some frameworks will be importing client on the server as part of SSR'ing content out, which means that you will also need checks like |
Also, you could run the tests on the emitted JS (as mentioned here https://learn.microsoft.com/en-us/visualstudio/javascript/unit-testing-javascript-with-visual-studio?view=vs-2022&tabs=mocha or use something like |
Regarding the I digged a bit and it seems an issue that many people faced. Among others evanw/esbuild#622 ...and the workarounds are like the wild west to insert the extension in emitted files. |
microsoft/TypeScript#16577 would rather be the curlpit. |
I'll try with https://github.com/AyogoHealth/jest-ts-webcompat-resolver later on... |
When use in browser there is no problem to use
client
But when I try to use in node.js,
client
was not foundWhat should I do to skip import
client
that I never useboth node.js 18 and 19
step to reproduce
The text was updated successfully, but these errors were encountered: