Skip to content

TypeScript cannot access types of @magic-ext/* packages when moduleResolution = "node16" in tsconfig.jsonΒ #669

Closed
@rjwebb

Description

@rjwebb

βœ… 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/@magic-ext+oidc@4.3.0/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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions