MonotterM
Denoβ€’3y agoβ€’
3 replies
Monotter

Importing local NodeJS module from Deno

Is it possible to import a javascript file that has
node
imports for standart modules like
http
just designed for
NodeJS
use?
For Example:
//main.ts [Deno]
import crypto from 'node:./module.js'
const data = crypto.createHmac('sha256', secret).update('I love cupcakes').digest('hex');
console.log(data)

//module.js [Node]
import crypto from 'crypto'
export { crypto }



I am asking this because, I am using
sveltekit-deno-adapter
to use
Svelte
on
Deno Deploy
. Unfortunately, when I use
Axios
on server-side script, it gives
Relative import path "events" not prefixed with / or ./ or ../ and not in import map from "file:///Users/x/x/x/x/build/server.js"
error when I start
Deno
after the build.

I can only think on 2 possibilities at this point, 1st one is forking
sveltekit-deno-adapter
to replace all
Node
imports with
node:
prefix before the import. And the 2nd is just using
fetch
on server-side code instead of
Axios
.

2nd one looks more reasonable in short term perspective but this issue is not happening only on
Axios
, do I have to throw away the modules that I use every time?
Was this page helpful?