`Deno.emit` with `bundle` emit type not working with JSON imports
Found by john.spurlock on Discord
Trying to bundle files through Deno.emit that import JSON Modules via import assertions fails. However, the expected behavior should be for the JSON imports to be handled in some way at compilation. Here's an example project:
// mod.ts
import data from "./data.json" assert { type: "json" };
console.log(data);
// build.ts
console.log(await Deno.emit("./mod.ts"));
// data.json
{ "age": 5 }
The expected result is to be a JavaScript bundle that correctly handles for the JSON imports. However, it instead shows the following error in the diagnostics:
{
category: 1,
code: 7042,
start: { line: 0, character: 20 },
end: { line: 0, character: 36 },
messageText: "Module './package.json' was resolved to 'file:///____/data.json', but '--resolveJsonModule' is not used.",
messageChain: null,
source: null,
sourceLine: 'import { age } from "./data.json" assert { type: "json" };',
fileName: "file:///____/build.ts",
relatedInformation: null
}
IMO it would be fine to instead just replace the
import FOO from "./bar.json" assert { type: "json" }
with
const FOO = JSON.parse(/* contents of "./bar.json" as a string */);
Along with the same behavior but Promise.resolve(..) for dynamic imports.
Note: this is what deno bundle already does.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.
Note: emit is working correctly now (not erroring), but json file is not inlined: