exhibitionist-digital / ultra

Zero-Legacy Deno/React Suspense SSR Framework
https://ultrajs.dev
MIT License
2.99k stars 66 forks source link

JSON import crash on client side #288

Open d9k opened 9 months ago

d9k commented 9 months ago
import schemaData from '/~/shared/api/supabase/schema.generated.json' assert {
  type: 'json',
};

console.log(schemaData);

Works on server side. On client side causes error

schema.generated.json:1 Failed to load module script: Expected a JSON module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
d9k commented 9 months ago

Ultra really just renders html page in response...

> curl http://localhost:8000/_ultra/compiler/src/shared/api/supabase/schema.generated.json

<!DOCTYPE html><html lang="en" data-mantine-color-scheme="dark"><head><meta charSet="utf-8"/>
<title>Ultra</title><meta name="viewport" content="width=device-width, initial-scale=1"/><lin
k rel="shortcut icon" href="/favicon.ico"/><script data-mantine-script="true">try {          
  var _colorScheme = window.localStorage.getItem("mantine-color-scheme-value");
  var colorScheme = _colorScheme === "light" || _colorScheme === "dark" || _colorScheme === "
auto" ? _colorScheme : "dark";
d9k commented 9 months ago

At least this line needs to be changed to support json:

lib/middleware/compiler.ts:

const isCompilerTarget = [".ts", ".tsx", ".js", ".jsx"].includes(extension);
d9k commented 9 months ago

Deployed my Ultra fork with fix JSON import fix at https://deno.land/x/ultra_fork_d9k@v2.3.8.1

Can't test with production build due to `/\~/` alias + build => Module not found on runtime | ultra issue #290

d9k commented 9 months ago

Seems to work on prod, preparing PR

d9k commented 9 months ago

PR https://github.com/exhibitionist-digital/ultra/pull/293

FalcoG commented 4 months ago

Good work on providing a fix. I've ran into the same issue, this seems really essential to have resolved.