Angular SSR Deno
I'm trying to run Angular ssr with Deno, but I get the following error.
deno run -A dist/deno-angular/server/server.mjs
error: Relative import path "fs/promises" not prefixed with / or ./ or ../
If you want to use a built-in Node module, add a "node:" prefix (ex. "node:fs/promises").
at file:///home/sheik/Documents/deno-angular/dist/deno-angular/server/server.mjs:105:1275
Do you know if there is a way to fix this?
9 Replies
Hi Sheik maybe there's a solution, is
server.mjs
a file you wrote yourself or a bundled js?bundled js
Okay I don't know if this can work but maybe if you create a
deno.json
file you can specify there an import map that tells deno where to find that fs/promises
import
let me see if I can emulate your issue
Yes it works!
so this is what you have to do:
1. create a deno.json
file in the root of your project (where you call that command from).
2. In that deno.json
config file add the following:
3. Done! Now you can run your command easily
Why?
Since Deno is not Node importing fs/promises
does not make any sense to it, this is why you have to tell it what's exactly you are trying to import by creating an import map
If you still have any issue let me knowHi @2saturdayscode , I've tried to import the map of everything it asked me to do, but now I get this error
Well at least it solved the other problem. Process should not be much different I think it behaves as an implicit import give me a couple of mins to test a potential solution
uhmm this is harder you, since
process
is not an import, but it does not mean anything outside Node
What version of Deno are you using?process can be imported from node:process
@Sheik if you need deno+angular SSR, consider using the primate module for angular: https://primatejs.com/modules/angular
Primate is almost 100% Deno-compatible.
Please note that this isn't the full-fledged angular server by the official angular team, which is quite heavy, but a reduced version only using the minimal amount of @angular packages needed to get up and running, and mostly focussed on SSR (no hydration yet).
However, it's been test-proven to work with Deno.
True, but since nobody does
import { process } from '???'
you can't just add an entry to the import map. It needs to be defined somehow at bundling time (to replace it with something from Deno)wow, thanks you
Deno 1.46.1