Sheik
Sheik5mo ago

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
2saturdayscode
2saturdayscode5mo ago
Hi Sheik maybe there's a solution, is server.mjs a file you wrote yourself or a bundled js?
Sheik
SheikOP5mo ago
bundled js
2saturdayscode
2saturdayscode5mo ago
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:
{
"imports": {
"fs/promises": "node:fs/promises"
}
}
{
"imports": {
"fs/promises": "node:fs/promises"
}
}
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 know
Sheik
SheikOP5mo ago
Hi @2saturdayscode , I've tried to import the map of everything it asked me to do, but now I get this error
Task dev deno run -A dist/deno-angular/server/server.mjs
error: Uncaught (in promise) ReferenceError: process is not defined
at file:///home/sheik/Documentos/deno-angular/dist/deno-angular/server/polyfills.server.mjs:4:14075
at Function.__load_patch (file:///home/sheik/Documentos/deno-angular/dist/deno-angular/server/polyfills.server.mjs:3:1189)
at ci (file:///home/sheik/Documentos/deno-angular/dist/deno-angular/server/polyfills.server.mjs:4:14043)
at li (file:///home/sheik/Documentos/deno-angular/dist/deno-angular/server/polyfills.server.mjs:4:15143)
at file:///home/sheik/Documentos/deno-angular/dist/deno-angular/server/polyfills.server.mjs:4:15163
[sheik@archlinux deno-angular]$
Task dev deno run -A dist/deno-angular/server/server.mjs
error: Uncaught (in promise) ReferenceError: process is not defined
at file:///home/sheik/Documentos/deno-angular/dist/deno-angular/server/polyfills.server.mjs:4:14075
at Function.__load_patch (file:///home/sheik/Documentos/deno-angular/dist/deno-angular/server/polyfills.server.mjs:3:1189)
at ci (file:///home/sheik/Documentos/deno-angular/dist/deno-angular/server/polyfills.server.mjs:4:14043)
at li (file:///home/sheik/Documentos/deno-angular/dist/deno-angular/server/polyfills.server.mjs:4:15143)
at file:///home/sheik/Documentos/deno-angular/dist/deno-angular/server/polyfills.server.mjs:4:15163
[sheik@archlinux deno-angular]$
2saturdayscode
2saturdayscode5mo ago
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?
coty
coty5mo ago
process can be imported from node:process
Berserkr [yol]
Berserkr [yol]5mo ago
@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.
2saturdayscode
2saturdayscode5mo ago
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)
Sheik
SheikOP4mo ago
wow, thanks you Deno 1.46.1

Did you find this page helpful?