dbushell/sveltekit-adapter-deno

Node Support

Closed this issue · 9 comments

My SvelteKit app makes use of the node fs and path modules, but it doesn't work, it says to write "platform": "node". Although this isn't supported by the old svelte-adapter-deno, but I think you can just turn the fs into node:fs in the imports.

In the build output can you try adding it to the import_map.json? Just add "fs": "node:fs" along with the other imports.

Deno Deploy only added support for node:fs like 2 days ago so the other adapter wouldn't have worked.

Maybe I need to add an option to pass additional imports. If you're unable to test I can try next week.

Ignore my previous comment.

As you suggested platform: "node" in the esbuild config fixed this – thanks!

I've updated the README. You can just do for example:

import * as fs from 'node:fs';
import {Buffer} from 'node:buffer';

In server routes and it should work.

Closing because fixed. It would be nice if the fs imports automatically got turned into node:fs, but it's fine.

Hello,

What about dependencies importing Node modules without node: ?

For example, @sideway/address, which is a dependency of joi, imports url, thus throwing Dynamic require of "url" is not supported when using this adapter, making it unusable :

Thanks

I'm not sure what it'd take to convert all node sub-dependencies in the bundle process. Deno's node compatibility isn't 100% so it wouldn't be guaranteed to work. Honestly I think you're best sticking with Node if requirements are so deep.

No, the issue isn't with Deno but with the adapter here, because this dependency works fine when importing it from a simple Deno script.

Yes I understand.

What I mean is the purpose of this adapter is only to deploy SvelteKit to Deno. It does not attempt to handle 3rd party Node dependencies and sub-dependencies.

That may be possible, but I have no plans to try because I don't think it's worth the effort. I think you're better deploying to Node if that is a requirement.

Okay, but then, in which real-life case is the adapter suitable ?

Because if it doesn't support a data validation library that natively works in all of Node, Deno and browsers, I can't imagine what happens when importing a library that most apps need, like a database connector 🤔

Thanks

There are plenty of websites that can be built with SvelteKit and have no 3rd party dependencies, or use JavaScript libraries that are not runtime specific. Loading data can be done via fetch APIs.

There is another Deno adapter but I don't think it can do what you want to achieve.

The difficulty is that SvelteKit is inherently a Node project. It's not easy going from Node in development to Deno in production.