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

Typescript support for moduleResolution: node #1816

Closed
5 tasks done
redbmk opened this issue Nov 21, 2024 · 4 comments
Closed
5 tasks done

Typescript support for moduleResolution: node #1816

redbmk opened this issue Nov 21, 2024 · 4 comments

Comments

@redbmk
Copy link

redbmk commented Nov 21, 2024

Checklist

  • I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Describe the problem you'd like to have solved

I'm using v4.0.0-beta.7 and my tsconfig.json has "moduleResolution": "node". I cannot import types via @auth0/nextjs-auth0/server as documented (webpack is able to load it ok). I've tried switching my module resolution to typescript's recommended suggestions ("node16", "nodenext", or "bundler"), however any of those end up breaking imports for other libraries I'm using.

Typescript can import from @auth0/nextjs-auth0/dist/server, but then webpack (potentially other bundlers as well) has issues importing from there.

Describe the ideal solution

Ideally we would be able to import the types even when moduleResolution is set to "node". This worked in v3 and I haven't run into this issue with any other libraries yet.

Alternatives and current workarounds

A workaround is to create a path alias in tsconfig:

{
  "compilerOptions": {
    // ...
    "paths": {
      "auth0/nextjs-auth0/server": ["node_modules/@auth0/nextjs-auth0/dist/server"],
      // ...
    }
   },
   // ...
}

Another possible workaround (untested) is to import from @auth0/nextjs-auth0/dist/server and teach the bundler (webpack in this case) how to handle that properly. This seems less ideal having to import from /dist.

Additional context

I was going to file this as a bug, but it requires checking that:

The issue can be reproduced in the nextjs-auth0 sample app (or N/A). *

...which is coded against v3 and doesn't seem to use typescript. It might be worth updating that to be an optional checkmark now that v4 is the main focus

@guabu guabu mentioned this issue Dec 5, 2024
@guabu
Copy link

guabu commented Dec 5, 2024

Hey @redbmk 👋 Thanks for reporting this! We're now including typeVersions which should help TypeScript resolve the types when the moduleResolution is set to node. This should be available in the next release.

@fated-x
Copy link

fated-x commented Dec 6, 2024

I ran into this same issue after attempting to upgrade my project to use v4.0.0-beta.9. However, the workaround provided by @redbmk didn't work for me. I am on the brink of giving up. Any idea when the next release will be pushed?

@guabu
Copy link

guabu commented Dec 6, 2024

Hey @fated-x, the next release should be out early next week!

@nandan-bhat
Copy link

This issue is fixed on 4.0.0-beta.10. Closing this ticket.

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

No branches or pull requests

4 participants