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 cannot access types of @magic-ext/* packages when moduleResolution = "node16" in tsconfig.json #669

Closed
3 tasks done
rjwebb opened this issue Nov 21, 2023 · 1 comment Β· Fixed by #670
Closed
3 tasks done
Labels
πŸ› Bug Report πŸ” Needs Triage released This issue/pull request has been released.

Comments

@rjwebb
Copy link
Contributor

rjwebb commented Nov 21, 2023

βœ… Prerequisites

  • Did you perform a cursory search of open issues? Is this bug already reported elsewhere?
  • Are you running the latest SDK version?
  • Are you reporting to the correct repository (magic-sdk)?

πŸ› Description

I'm currently exploring how my team can integrate Magic into an existing web app which was using Node16 module resolution. I found that if I tried to import any @magic-ext/* packages then I would get an error with some variation on:

src/main.ts:15:18 - error TS7016: Could not find a declaration file for module '@magic-ext/oidc'. '/Users/bob/code/work/canvas/magic-module-import-reproduce/node_modules/.pnpm/@[email protected]/node_modules/@magic-ext/oidc/dist/es/index.mjs' implicitly has an 'any' type.
  There are types at '/Users/bob/code/work/canvas/magic-module-import-reproduce/node_modules/@magic-ext/oidc/dist/types/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@magic-ext/oidc' library may need to update its package.json or typings.

15 import oidc from "@magic-ext/oidc"
                    ~~~~~~~~~~~~~~~~~

replacing "@magic-ext/oidc" with the particular module being imported.

I think this is a pretty big deal - if we want Magic to be supported by modern web apps then we should be supporting more recent module resolution methods. I'm happy to make a PR for this.

🧩 Steps to Reproduce

  1. Create a Typescript project that uses Node16 or NodeNext for the module and moduleResolution settings in tsconfig.json
  2. Try to import something from @magic-ext/*

You should see an error in tsc looking something like the quoted text in the description of this issue.

πŸ’» Code Sample

I've created a repo that provides a minimal example that triggers this error.

https://github.com/rjwebb/magic-module-import-reproduce

🌎 Environment

Software Version(s)
magic-sdk N/A
Browser N/A
yarn I used pnpm 8.10.0
Operating System Mac OS

Solution?

I think I know how to solve this - we just need to add a types value to the exports object in package.json for the affected packages, i.e. copy the fix in #626

@rjwebb rjwebb changed the title Cannot import @magic-ext/* packages when moduleResolution = "node16" in tsconfig.json TypeScript cannot access types of @magic-ext/* packages when moduleResolution = "node16" in tsconfig.json Nov 21, 2023
@Ariflo Ariflo added the released This issue/pull request has been released. label Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
πŸ› Bug Report πŸ” Needs Triage released This issue/pull request has been released.
Projects
None yet
2 participants