fresh icon indicating copy to clipboard operation
fresh copied to clipboard

ERROR: [plugin: deno] Unhandled media type Json.

Open ClaudiuCeia opened this issue 2 years ago • 4 comments

I'm using a deno library that imports a JSON file with:

import countries from "https://cdn.jsdelivr.net/gh/umpirsky/[email protected]/data/en_US/country.json" assert { type: "json" };

This is happening in the code for an island, what I get in the console is:

Loading module from “http://localhost:8000/_frsh/js/63eb35c3-6547-4f71-9fc2-b111894c1374/island-playground.js” was blocked because of a disallowed MIME type (“text/html”)

And going to the URL in this error gives me:

An error occured during route handling or page rendering.

Error: Build failed with 2 errors:
deno:https://deno.land/x/[email protected]/src/Location.ts:11:22: ERROR: [plugin: deno] Unhandled media type Json.
deno:https://deno.land/x/[email protected]/src/URL.ts:19:17: ERROR: [plugin: deno] Unhandled media type Json.
    at failureErrorWithLog (https://deno.land/x/[email protected]/mod.js:1572:15)
    at https://deno.land/x/[email protected]/mod.js:1218:28
    at runOnEndCallbacks (https://deno.land/x/[email protected]/mod.js:1001:63)
    at buildResponseToResult (https://deno.land/x/[email protected]/mod.js:1216:7)
    at https://deno.land/x/[email protected]/mod.js:1325:14
    at https://deno.land/x/[email protected]/mod.js:633:9
    at handleIncomingPacket (https://deno.land/x/[email protected]/mod.js:730:9)
    at readFromStdout (https://deno.land/x/[email protected]/mod.js:599:7)
    at https://deno.land/x/[email protected]/mod.js:1846:11

So my question is, are JSON imports not allowed in islands? And if they're allowed - what am I doing wrong? The library should work as expected, at least it does when I run the test suites.

Thanks

ClaudiuCeia avatar Jul 21 '22 14:07 ClaudiuCeia

Quick follow up - this works in API routes. I'm probably missing the bigger picture here, but why can't json modules be resolved like ts modules for client side code too?

ClaudiuCeia avatar Jul 21 '22 16:07 ClaudiuCeia

This is a bug in Fresh. Thanks for reporting!

lucacasonato avatar Jul 22 '22 16:07 lucacasonato

I wonder: is the problem I'm running into the same propblem or a different one:

I have a json file in my project that I'm importing as part of some util which also imported as part routes/*.tsx (and used in the server side code).

When the server restarts after detecting changes it complains the following:

error: SyntaxError: The requested module '../static/deployments.json' does not provide an export named 'repositoryBase'
    at async dev (https://deno.land/x/[email protected]/src/dev/mod.ts:163:3)
    at async file:///run/media/karfau/hdd-data/dev/fresh-spike/dev.ts:5:1

karfau avatar Jul 30 '22 13:07 karfau

That is likely a different bug - you are probably importing JSON in the form of import { foo } from "./data.json" assert { type: "json" } instead of import data from "./data.json" assert { type: "json" }`. JSON imports only allow importing the entire value as a default import.

lucacasonato avatar Jul 30 '22 15:07 lucacasonato

This is fixed in Fresh 1.0.2.

lucacasonato avatar Jul 31 '22 21:07 lucacasonato