jnsmalm / pixi3d

The 3D renderer for PixiJS. Seamless integration with 2D applications.
https://pixi3d.org
MIT License
752 stars 43 forks source link

Crashes with "Unrecognized source type to auto-detect resource" when imported in NodeJS #199

Open patreeceeo opened 6 months ago

patreeceeo commented 6 months ago

Steps to reproduce

  1. start node interactive shell
  2. import("pixi3d/pixi7")

Stack trace

Uncaught Error: Unrecognized source type to auto-detect Resource
    at autoDetectResource (file:///.../node_modules/@pixi/core/lib/textures/resources/autoDetectResource.mjs:15:9)
    at new _BaseTexture2 (file:///.../node_modules/@pixi/core/lib/textures/BaseTexture.mjs:46:64)
    at Texture.from (file:///.../node_modules/@pixi/core/lib/textures/Texture.mjs:125:155)

What I expected

It can be imported in Node without crashing. What I've read on in this project's discussions leads me to believe this should be possible.

jnsmalm commented 6 months ago

Why do you want to do this in an interactive shell?

patreeceeo commented 6 months ago

In my case, for automated testing.

patreeceeo commented 6 months ago

To clarify, the issue isn't only in the Node CLI/interactive shell. It's in any Node context. Besides automated tests, library users may want to SSR.

patreeceeo commented 6 months ago

I think the argument could also be made it's a general usability issue when a module is written such that it assumes and creates a hard dependency on a certain environment at import time?

jnsmalm commented 6 months ago

In general, Pixi3D has not been created to be imported in any environment. If you want to dig deeper and provide a solution I'm happy to accept a PR.

jnsmalm commented 6 months ago

Btw, Pixi3D itself has automated tests. Maybe you can have a look at those and see how it works?