Skip to content

Could not find a declaration file for module 'react-ogl' on Next.js 15 #85

@NickAnthony

Description

@NickAnthony

What’s happening?

When a project uses modern module resolution (e.g. Next 15’s default "moduleResolution": "bundler" or any environment that honours the exports map), TypeScript can’t see react-ogl’s declaration file:

Could not find a declaration file for module 'react-ogl'

react-ogl does ship ./dist/index.d.ts and even declares it via
"types": "./dist/index.d.ts", but the package’s exports map only exposes JavaScript:

"exports": "./dist/index.mjs"

Once an exports map is present, Node & TS ignore the legacy types field and rely solely on the map.
Because index.d.ts isn’t referenced there, resolvers treat the package as untyped.

Minimal reproduction

  1. npx create-next-app@latest --typescript (Next 15)

  2. yarn add ogl react-ogl

  3. Add a file:

    import { Canvas } from 'react-ogl';
    //   ❌  TS7016: Could not find a declaration file …
  4. Run yarn tsc – the error appears.

Expected behaviour

TypeScript should pick up the shipped declarations without extra config or patches.

Actual behaviour

Typings are invisible

Fix (I think this should fix it)

Expose the type file inside the exports map:

- "exports": "./dist/index.mjs",
+ "exports": {
+   ".": {
+     "import": "./dist/index.mjs",
+     "types":  "./dist/index.d.ts"
+   }
+ },

This would be backwards-compatible (old Node/TS still read main/module/types)

My Environment

package version
react-ogl 0.15.0
ogl 1.0.11
typescript 5.3.x
next 15.x
node 20.x

Thanks for the great library!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions