pmndrs / gltfjsx

🎮 Turns GLTFs into JSX components
https://gltf.pmnd.rs
MIT License
4.7k stars 310 forks source link

Error running gltfjsx with npx #201

Open vegancat opened 1 year ago

vegancat commented 1 year ago

runnin npx gltfjsx <model> <options> throws error below:

gltfjsx is not recognized as an internal or external command,
operable program or batch file.

seems to be a node18 incompatibility error but not sure.

it's happening after new changes were pushed recently. yesterday it was working without any problem

Node version: 18.6.0 OS: Win11

drcmda commented 1 year ago

hm, doesn't seem related to node 18

~/Downloads  main ✔                                                                       125d20h  ⍉
▶ nvm use node
Now using node v18.6.0 (npm v8.13.2)

~/Downloads  main ✔                                                                        125d20h  
▶ npx gltfjsx kitchen.glb --transform --simplify --keepmeshes --resolution=2048        
Need to install the following packages:
  gltfjsx@6.2.3
Ok to proceed? (y) y
instance: No meshes with ≥5 parent nodes were found.
prune: No unused properties found.
prune: Removed types... Accessor (3)
prune: No unused properties found.
prune: Removed types... Accessor (8)
prune: No unused properties found.
group walls removed (empty)
group lamp removed (empty)
group charis removed (empty)
group plant removed (empty)
group cuttingboard removed (empty)
group Scene removed (empty)
vegancat commented 1 year ago

Wierd then it has to be something on my side!

vegancat commented 1 year ago

I seem to have problem with npx! I tried npm exec gltfjsx <model> <options> and I got error below:

npm exec gltfjsx@latest .\RockLarge3.glb -T
node:internal/errors:490
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'sharp' imported from <some system path ;)>\AppData\Local\npm-cache\_npx\fbe31d99a7fa405b\node_modules\gltfjsx\src\utils\transform.js
    at new NodeError (node:internal/errors:399:5)
    at packageResolve (node:internal/modules/esm/resolve:889:9)
    at moduleResolve (node:internal/modules/esm/resolve:938:20)
    at defaultResolve (node:internal/modules/esm/resolve:1153:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
    at link (node:internal/modules/esm/module_job:76:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v18.16.0

I know what sharp is but, these kinds of errors mean some directory is miss-located in the npm config and it's unable to resolve packages.

Maybe I need to find the local registry for downloaded packages and manually delete the package.

vegancat commented 1 year ago

For anyone facing the same issue:

seems like sharp is being used in the package but somehow is not included in dependencies.

1- I opened the _npx cache with the path in error from message above: <some system path ;)>\AppData\Local\npm-cache\_npx\fbe31d99a7fa405b

2- installed the missing sharp package (npm install didn't work so I had to be more specific):

npm install --arch=x64 --platform=win32 sharp

3- when using don't forget the @latest tag!:

npx gltfjsx@latest <model> <options>
marcel-codett commented 1 year ago

i got a similar error. gltf

1kaiser commented 1 year ago

https://github.com/pmndrs/gltfjsx/issues/207#issuecomment-1605890811

verekia commented 11 months ago

This still happens with Node v20.8.1 and npx.

> node -v
v20.8.1
> npx gltfjsx model.glb -t -T -S
model.glb does not exist.
1kaiser commented 11 months ago

this works ✅🥳👍in colab code

!npm install -g n 
!n 20.8.1

!npm i gltfjsx
!wget https://cdn-luma.com/71fb8d424f400eaa324e6f9d4bf6f2af74cefb319d057afb277cc46c838ed940/Yttgh_textured_mesh_glb.glb -O a.glb
output = f'/content/a.glb'
!npx gltfjsx {output} -t -T -S

outputs

prune: No unused properties found.
prune: Removed types... Accessor (356)
instance: No meshes with ≥5 parent nodes were found.
prune: No unused properties found.
prune: No unused properties found.
prune: No unused properties found.
prune: No unused properties found.
prune: No unused properties found.
prune: No unused properties found.
/*
Auto-generated by: https://github.com/pmndrs/gltfjsx
Command: npx gltfjsx@6.2.13 /content/a.glb -t -T -S 
Files: /content/a.glb [68.23MB] > a-transformed.glb [20.4MB] (70%)
*/
verekia commented 11 months ago

I am talking about not installing gltfjsx but using it directly with npx gltfjsx, which is great for 1-shot CLI tools that you don't want to have in your dependencies or in your node_modules. Can you try again without npm i gltfjsx please?

Maybe the path used by gltfjsx is relative to the binary executable location, in which case it would be in some system folder rather than the project folder.