question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PIXI types not loading in ESM project

See original GitHub issue

Circa the latest version of pixi, I am unable to have typescript resolve the pixi import because it cannot find the associated types file. This is likely due to it resolving the import to dist/cjs/pixi.js, and attempting to find the .d.ts in that folder instead of index.d.ts.

Expected Behavior

pixi.js is able to be included by typescript in ESM mode

Current Behavior

Typescript is unable to find the types for it

Possible Solution

This can be fixed via adjustments to the package.json (in my case at least, not sure if there are other cases I’m not thinking about)

For more detail, see this page from the ts 4.7 release notes

{
  "exports": {
    ".": {
       "import": {
          "default": "dist/esm/pixi.js",
          "types": "index.d.ts"
       },
       "require": {
          "default": "dist/cjs/pixi.js",
          "types": "index.d.ts"
       }
    }
  },
  "types": "index.d.ts"
}

Steps to Reproduce

Create a new project with ts 4.7 and pixi. In the compiler options, set module to NodeNext and in the package.json set type to module. Create a new typescript file and import something from pixi.js. Typescript will throw an error.

Environment

  • pixi.js version: 6.3.2
  • typescript version: 4.7.2
  • Browser & Version: N/A
  • OS & Version: MacOS 12.1
  • Running Example: N/A (could probably throw one together if needed)

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
bigtimebuddycommented, May 29, 2022

All packages, please!

1reaction
bigtimebuddycommented, May 29, 2022

I don’t think there is much harm in this as it is backward compatible. This all seem rather new but would unblock 4.7+ TS users.

So yeah, PR welcome. Thanks for offering.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PIXI import not working: Cannot find module pixi.js
The problem is that this loses the type information I want. Pixi has a d.ts file, so I should be getting types. What...
Read more >
Help error when build pixijs with typescript and wepack - Pixi.js
i use webpack, typescript and pixijs to build my app. But when i build it has error: ERROR in ./node_modules/pixi.js/lib/index.js Module not ...
Read more >
pixi-viewport - npm
A highly configurable viewport/2D camera designed to work with pixi.js. Features include dragging, pinch-to-zoom, mouse wheel zooming, ...
Read more >
Compiling and bundling TypeScript libraries with Webpack
The problem comes with the fact that type declarations files aren't valid ... the compiler options and to indicate that the folder is...
Read more >
react-pixi-fiber/Lobby - Gitter
I am trying to build a simple project with typescript + react-pixi-fiber. and getting the following error: Compiled with problems:X ERROR in ....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found