Open Ciantic opened 1 month ago
Here is same project with Bun for comparison:
I have investigated more, it comes from vite's ESM Module importer in here:
https://github.com/vitejs/vite/blob/main/packages/vite/src/module-runner/esmEvaluator.ts#L32-L38
const initModule = new AsyncFunction(
ssrModuleExportsKey,
ssrImportMetaKey,
ssrImportKey,
ssrDynamicImportKey,
ssrExportAllKey,
// source map should already be inlined by Vite
'"use strict";' + code,
)
await initModule(
context[ssrModuleExportsKey],
context[ssrImportMetaKey],
context[ssrImportKey],
context[ssrDynamicImportKey],
context[ssrExportAllKey],
)
Some reasons it works in bun with special imports but not with deno.
Ahaa! Found the culprit! Vite has whitelisted what are Deno/Bun imports here:
It is missing jsr!
NOTICE also very important comment:
// Supported by Node, Deno, Bun
const NODE_BUILTIN_NAMESPACE = 'node:'
// Supported by Deno
const NPM_BUILTIN_NAMESPACE = 'npm:'
// Supported by Bun
const BUN_BUILTIN_NAMESPACE = 'bun:'
// Some runtimes like Bun injects namespaced modules here, which is not a node builtin
const nodeBuiltins = builtinModules.filter((id) => !id.includes(':'))
// TODO: Use `isBuiltin` from `node:module`, but Deno doesn't support it
export function isBuiltin(id: string): boolean {
if (process.versions.deno && id.startsWith(NPM_BUILTIN_NAMESPACE)) return true
if (process.versions.bun && id.startsWith(BUN_BUILTIN_NAMESPACE)) return true
return isNodeBuiltin(id)
}
Deno is missing isBuiltin
support so they have whitelisted things!
I made a pull request to support jsr:
imports in vite:
https://github.com/vitejs/vite/pull/18479
It is not fully resolved yet, I get more errors
Why can't you use the deno official vite plugin for that? https://github.com/denoland/deno-vite-plugin
Why can't you use the deno official vite plugin for that? https://github.com/denoland/deno-vite-plugin
Never mind, I tried and it did resolve the imports but got a different error, I'll create a repro for that and create and issue with deno/vinxi unsure where the issue is, but jsr resolver is working
I'm starting to think this is not possible, because jsr:
imports are not possible in Deno's node compatibility mode.
With pure deno mode I have test repo:
https://github.com/Ciantic/deno-pure-solid-start
But it yields even more weirder errors:
[h3] [unhandled] Error: Failed to load url ./src/database.ts (resolved id: ./src/database.ts) in deno::TypeScript::@db/sqlite::C:/Users/jarip/AppData/Local/deno/remote/https/jsr.io/ff2127150c5fc24dbc6b1daba62c248f566cce7c9346539da1003b4019d972c2. Does the file exist?
Duplicate of #23929.
Deno version: deno --version deno 2.0.2 (stable, release, x86_64-pc-windows-msvc) v8 12.9.202.13-rusty typescript 5.6.2
Here is a repo: https://github.com/Ciantic/deno-pure-solid-start
Discord link