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

bug: Rollup Error in Nuxt while importing logtoEventHandler from @logto/nuxt #909

Open
vacijj opened this issue Jan 22, 2025 · 3 comments
Open
Labels
bug Something isn't working

Comments

@vacijj
Copy link

vacijj commented Jan 22, 2025

Describe the bug

If I create a server/api/auth/get-access-token.ts as described in Use in middleware or API routes, the following error occurs.

ERROR  RollupError: [plugin impound] Importing directly from module entry-points is not allowed. [importing @logto/nuxt from server/api/auth/get-access-token.ts]


undefined

The same error occurs in a server middleware.

Expected behavior

No error must occur.

How to reproduce?

See reproduction example.

@vacijj vacijj added the bug Something isn't working label Jan 22, 2025
@vacijj
Copy link
Author

vacijj commented Jan 30, 2025

@wangsijie I see that you were assigned to other nuxt related issues. Do you have an idea?

@wangsijie
Copy link
Contributor

Will take a look

@ac-shadow
Copy link

ac-shadow commented Feb 13, 2025

I just ran into the same issue. I am not too familiar with nuxt modules however i've looked at some other modules and noticed that they define an alias for the server side imports.

For example in the sidebase nuxt-auth module (https://github.com/sidebase/nuxt-auth/blob/956b0fa1b5aed3fb94a47563a9e47dc811940a6a/src/module.ts#L170-L182)

// 5. Create virtual imports for server-side
nuxt.hook('nitro:config', (nitroConfig) => {
  nitroConfig.alias = nitroConfig.alias || {}

  // Inline module runtime in Nitro bundle
  nitroConfig.externals = defu(
    typeof nitroConfig.externals === 'object' ? nitroConfig.externals : {},
      {
        inline: [resolve('./runtime')]
      }
    )
    nitroConfig.alias['#auth'] = resolve('./runtime/server/services')
  })

I've created a pnpm patch to try this out and it seems to solve the issue

// patches/@logto__nuxt.patch
diff --git a/dist/module.mjs b/dist/module.mjs
index 5326963aa51fcc0427ea183a0d8388c4d1ac830f..c258ebbfdd55761ec4762c3931f0f6bd84ecdc47 100644
--- a/dist/module.mjs
+++ b/dist/module.mjs
@@ -35,6 +35,10 @@ const logtoModule = defineNuxtModule({
       handler: resolve("./runtime/server/event-handler")
     });
     addImportsDir(resolve("./runtime/composables"));
+    nuxt.hook("nitro:config", (nitroConfig) => {
+      nitroConfig.alias = nitroConfig.alias || {};
+      nitroConfig.alias["#logto"] = resolve("./runtime/utils/handler.js");
+    });
   }
 });

I just had to change the import in my api route to use the new alias like this
import { logtoEventHandler } from "#logto";

I also noticed that typescript cannot find a type definition for "event.context.logtoClient" so it just returns "any".

Image

I think this can be solved by adding a type declaration to the module like it is described here: https://nuxt.com/docs/guide/going-further/modules#adding-type-declarations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

3 participants