maarteNNN
maarteNNN6mo ago

How to use Deno modules in Vite app (Vue specifically)

I scaffolded an app using https://docs.deno.com/runtime/tutorials/how_to_with_npm/vue#run-npmcreate-vite-extra. I'm trying to use the SurrealDB package inside Vue but stumbling upon an error:
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "application/typescript". Strict MIME type checking is enforced for module scripts per HTML spec.
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "application/typescript". Strict MIME type checking is enforced for module scripts per HTML spec.
I tried using the vite-deno-plugin but stumbled on the same results. Anyone have any success making Deno TS modules work in Vite?
How to use Vue with Deno | Deno Docs
Vue is a progressive front-end JavaScript framework, built
1 Reply
Deno AI Helper
Deno AI Helper6mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the error message you've provided, it seems like there might be an issue with how the TypeScript files are being served. The error indicates that the server is responding with a MIME type of "application/typescript" when a JavaScript module script is expected. One possible reason for this error could be that the TypeScript files are not being compiled to JavaScript before being served to the browser. Vite is designed to work with JavaScript modules, and while it does support TypeScript, it expects TypeScript to be compiled to JavaScript during the build process or on-the-fly during development. Since you are trying to use Deno modules, which are typically written in TypeScript, you need to ensure that they are compiled to JavaScript. The vite-deno-plugin you mentioned is supposed to handle this by compiling TypeScript with Deno and then serving the resulting JavaScript to Vite. Make sure that you have configured the plugin correctly in your vite.config.js file. Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of the advice given. Additionally, you may want to consult the documentation or community for vite-deno-plugin or seek help from the Vite community for more specific guidance on integrating Deno modules with Vite.