Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running Nitro's Node.js mode with Deno #2224

Closed
littledivy opened this issue Mar 6, 2024 · 1 comment · Fixed by #2225
Closed

Running Nitro's Node.js mode with Deno #2224

littledivy opened this issue Mar 6, 2024 · 1 comment · Fixed by #2225

Comments

@littledivy
Copy link
Contributor

I'm working on Nuxt.js compatbility in Deno with the goal to get the default Node adapter working. There is only one blocker that is hard to solve on Deno's side:

The Node.js rollup depends on the process global. Deno requires an explicit import to node:process for files outside node_modules. Would it be make sense to emit the import? Here's my patch:

diff --git a/src/rollup/plugins/import-meta.ts b/src/rollup/plugins/import-meta.ts
index 4a96579..d74ac99 100644
--- a/src/rollup/plugins/import-meta.ts
+++ b/src/rollup/plugins/import-meta.ts
@@ -18,13 +18,14 @@ export function importMeta(nitro: Nitro): Plugin {
         nitro.options.node && isEntry
           ? "_import_meta_url_"
           : '"file:///_entry.js"';
+      const envImport = nitro.options.node ? "import process from 'node:process';" : "";
       const env = nitro.options.node ? "process.env" : "{}";
       const ref = "globalThis._importMeta_";
       const stub = `{url:${url},env:${env}}`;
       const stubInit = isEntry ? `${ref}=${stub};` : `${ref}=${ref}||${stub};`;

       return {
-        code: stubInit + code,
+        code: envImport + stubInit + code,
         map: null,
       };
     },
@pi0
Copy link
Member

pi0 commented Mar 6, 2024

Hi. Feel free to make a PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants