Closed blumgart closed 1 year ago
Hey @blumgart!
Thanks for the report ❤️
Two points:
Hey @BracketJohn, here's a minimal repro for this issue: https://stackblitz.com/edit/github-srfkuq-6hre7g?file=nuxt.config.ts (rc.12 stable)
Note that this will work on StackBlitz, but running this project's dev server locally on a Windows 11 machine will throw the error reported above. You may need to remove the "HOST=0.0.0" added to the run script in the package.json file for it to start properly.
Thanks @Yan-Thomas - I'll check it out and we'll fix it ASAP!
I would guess this is a common problem with modules and that it's related to how we resolve paths, e.g., here: https://github.com/sidebase/nuxt-session/blob/d6ea714d68cc40d4535f2e9ad940687beee34107/src/module.ts#L154-L157
Is this the right approach / is this a known problem?
Hi, @BracketJohn.
I made a few changes and now everything works, can you check it yourself?
diff --git a/node_modules/@sidebase/nuxt-session/dist/module.mjs b/node_modules/@sidebase/nuxt-session/dist/module.mjs
index 4adffd5..fad4400 100644
--- a/node_modules/@sidebase/nuxt-session/dist/module.mjs
+++ b/node_modules/@sidebase/nuxt-session/dist/module.mjs
@@ -1,6 +1,4 @@
-import { resolve } from 'path';
-import { fileURLToPath } from 'url';
-import { defineNuxtModule, useLogger, addServerHandler, addImportsDir } from '@nuxt/kit';
+import { defineNuxtModule, useLogger, addServerHandler, addImportsDir, createResolver } from '@nuxt/kit';
import { defu } from 'defu';
const PACKAGE_NAME = "nuxt-session";
@@ -40,8 +38,8 @@ const module = defineNuxtModule({
options.api.methods = moduleOptions.api.methods.length > 0 ? moduleOptions.api.methods : ["patch", "delete", "get", "post"];
nuxt.options.runtimeConfig.session = defu(nuxt.options.runtimeConfig.session, options);
nuxt.options.runtimeConfig.public = defu(nuxt.options.runtimeConfig.public, { session: { api: options.api } });
- const runtimeDir = fileURLToPath(new URL("./runtime", import.meta.url));
- const handler = resolve(runtimeDir, "server/middleware/session");
+ const { resolve } = createResolver(import.meta.url);
+ const handler = resolve("./runtime/server/middleware/session");
const serverHandler = {
middleware: true,
handler
@@ -49,14 +47,14 @@ const module = defineNuxtModule({
nuxt.options.serverHandlers.unshift(serverHandler);
if (options.api.isEnabled) {
for (const apiMethod of options.api.methods) {
- const handler2 = resolve(runtimeDir, `server/api/session.${apiMethod}`);
+ const handler2 = resolve(`./runtime/server/api/session.${apiMethod}`);
addServerHandler({ handler: handler2, route: options.api.basePath });
}
logger.info(`Session API "${options.api.methods.join(", ")}" endpoints registered at "${options.api.basePath}"`);
} else {
logger.info("Session API disabled");
}
- const composables = resolve(runtimeDir, "composables");
+ const composables = resolve("./runtime/composables");
addImportsDir(composables);
logger.success("Session setup complete");
}
Thanks @blumgart - we're going to test out the changes + merge + publish it. If the changes are fine we're going to release 0.2.2 with a fix today or tomorrow! 🚀
I've handed this to @zoey-kaiser (:
Hi @blumgart!
Thank you for reporting this bug! I opened a new Pull Request (#13) and implemented your changes. Based on my testing the module now works on windows!
You are welcome to clone the repository and test it out yourself!
@blumgart / @Yan-Thomas we'll do a release within the next hour that you can then directly use (:
@blumgart and @Yan-Thomas release is out: https://github.com/sidebase/nuxt-session/releases/tag/0.2.2
Feel free to give feedback (:
Environment
Windows_NT
v16.15.0
3.0.0-rc.13-27776700.5a88510
0.6.1-27776717.ed4c0f8
yarn@1.22.17
vite
app
,build
,buildModules
,googleFonts
,modules
,routeRules
@sidebase/nuxt-session@0.2.1
,@nuxtjs/tailwindcss@5.3.5
,@nuxtjs/strapi@1.6.1
,nuxt-icon@0.1.7
Build Modules:
@nuxtjs/google-fonts@3.0.0-0
Reproduction
No response
Describe the bug
On Windows 11 i have this error
[worker reload] [worker init] Only URLs with a scheme in: file, data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'e:'
Additional context
No response
Logs