sidebase / nuxt-auth

Authentication built for Nuxt 3! Easily add authentication via OAuth providers, credentials or Email Magic URLs!
https://auth.sidebase.io
MIT License
1.23k stars 158 forks source link

Package import specifier "#auth" is not defined in package #816

Closed agracia-foticos closed 1 week ago

agracia-foticos commented 1 month ago

Environment

Reproduction

If i compile with npm run dev throws this error

ERROR [nuxt] [request error] [unhandled] [500] Package import specifier "#auth" is not defined in package /home/foticos/var/www/wpx/packages/auth-internal/package.json imported from /home/foticos/var/www/wpx/packages/auth-internal/dist/runtime/server/api/auth/[...].js

with npx nuxi build and start server not fails

Describe the bug

If i compile with npm run dev throws this error

ERROR [nuxt] [request error] [unhandled] [500] Package import specifier "#auth" is not defined in package /home/foticos/var/www/wpx/packages/auth-internal/package.json imported from /home/foticos/var/www/wpx/packages/auth-internal/dist/runtime/server/api/auth/[...].js

with npx nuxi build and start server not fails

Additional context

No response

Logs

No response

phoenix-ru commented 1 month ago

We haven't encountered such an issue, could you please provide more information or create a reproduction? Having at least nuxt.config.ts would help

github-actions[bot] commented 1 month ago

Hello 👋

Please provide a reproduction for this issue 🙏

How can I create a reproduction? Please use one of the following links to reproduce your issue. - https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz - https://codesandbox.io/s/github/nuxt/starter/v3-codesandbox Please ensure that the reproduction is as **minimal** as possible. This will allow us to isolate the issue as best as possible. Here are some more amazing posts about the importance of reproductions: - [The Importance of Reproductions](https://antfu.me/posts/why-reproductions-are-required) - [How to Generate a Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/minimal-reproducible-example)
agracia-foticos commented 1 month ago

https://stackblitz.com/edit/nuxt-starter-irb91s

This is an example. In this reproduction i put the module.

My project implements this module in nuxt.config.ts modules : ['nuxt-sso']

phoenix-ru commented 1 month ago

Hi @agracia-foticos , I checked your reproduction and I think the problem is actually in the addServerScanDir in your module.ts which seems to just transpile TypeScript to JS and nothing else.

Investigation

You can look at the code produced by it in the dist folder inside your reproduction if you run npm run prepack && npm run dev. The code is simply transpiled, snippet:

// dist/runtime/server/api/auth/[...].js

import { NuxtAuthHandler } from "#auth";
export default NuxtAuthHandler({
  secret: useRuntimeConfig().authSecret,
  providers: [

It is very easy to verify that nuxt-auth is not a culprit by simply doing this in your [...].ts:

// import { NuxtAuthHandler } from '#auth';

function NuxtAuthHandler(config) {
  console.log(config);
}

export default NuxtAuthHandler({
  secret: useRuntimeConfig().authSecret,

  providers: [

In this case you get a different error:

[nuxt] [request error] [unhandled] [500] useRuntimeConfig is not defined

And it is obvious that auto-imports were not injected and no usual "Nuxt magic" happened.

Proposal

I would recommend you to approach the unjs/nitro team with the reproduction which is almost good already. I had to adjust your module.ts to make it work

baseURL: `${process.env.NUXT_BASE_URL ?? ''}/api/auth`

I couldn't find addServerScanDir in the Nitro web documentation and haven't looked into their source code.

There are also Nuxt Layers which seem to accomplish a similar thing as your meta-module.

zoey-kaiser commented 1 week ago

Hi @agracia-foticos 👋

I have tested this issue in a couple of new projects and do belive the issue is the one outlined above by @phoenix-ru. I will close this issue, as we have not heard from you in a while. If the issue persists feel free to re-open the issue!