pmndrs / drei

🥉 useful helpers for react-three-fiber
https://docs.pmnd.rs/drei
MIT License
8.46k stars 714 forks source link

Error: require() of ES modules is not supported. #450

Closed Xapu1337 closed 3 years ago

Xapu1337 commented 3 years ago

Hey I'm using @react-three/fiber & drei it worked in the beginning then I've got a massive error something like:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\Users\XapuR\OneDrive\xapu1337-website\node_modules\three-mesh-bvh\src\index.js
require() of ES modules is not supported.
require() of C:\Users\XapuR\OneDrive\xapu1337-website\node_modules\three-mesh-bvh\src\index.js from C:\Users\XapuR\OneDrive\xapu1337-website\node_modules\@react-three\drei\index.cjs.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES module
s.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Users\XapuR\OneDrive\xapu1337-website\node_modules\three-mesh-bvh\package.json.

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1080:13)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (C:\Users\XapuR\OneDrive\xapu1337-website\node_modules\@react-three\drei\index.cjs.js:1:699)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14) {
  code: 'ERR_REQUIRE_ESM'
}

The source to this file can be found here

Xapu1337 commented 3 years ago

Any ideas how to fix it?

joshuaellis commented 3 years ago

@Xapu1337, please provide a small reproduction of the error

drcmda commented 3 years ago

imo there is no fix. this is coming from nodes wonderful new module system and indirectly from other packages that now aren't compatible any longer, in this case three-mesh-bvh. someone needs to tell them to change their package.

joshuaellis commented 3 years ago

Well the fix is to remove the feature until it's resolved in the library if anything.

drcmda commented 3 years ago

i agree, removing it is probably for the best.

ragnorc commented 3 years ago

Well the fix is to remove the feature until it's resolved in the library if anything.

@joshuaellis What do you mean by "remove" the feature?

Is there any to fix this for us before it gets fixed in three-mesh-bvh?

drcmda commented 3 years ago

only by going back in version history. the fix should be easy for them, i hope this can be fixed quickly but no response yet.

3dln commented 3 years ago

Same error here and this makes drei completely unusable, so makes sense to remove the feature until they fix the bug

3dln commented 3 years ago

only by going back in version history. the fix should be easy for them, i hope this can be fixed quickly but no response yet.

Which version is OK to use @drcmda?

joshuaellis commented 3 years ago

only by going back in version history. the fix should be easy for them, i hope this can be fixed quickly but no response yet.

Which version is OK to use @drcmda?

The last 0.X.0 version. We use semver so it's easy to understand.

Xapu1337 commented 3 years ago

only by going back in version history. the fix should be easy for them, i hope this can be fixed quickly but no response yet.

Which version is OK to use @drcmda?

The last 0.X.0 version. We use semver so it's easy to understand.

The last drei version? Because if drei is currently v6.2.0 v0.X.0 sounds a bit outdated? or maybe I'm wrong

3dln commented 3 years ago

only by going back in version history. the fix should be easy for them, i hope this can be fixed quickly but no response yet.

Which version is OK to use @drcmda?

The last 0.X.0 version. We use semver so it's easy to understand.

The last drei version? Because if drei is currently v6.2.0 v0.X.0 sounds a bit outdated? or maybe I'm wrong

It is 6.X.0, I used 6.1.0 and the error is gone

joshuaellis commented 3 years ago

I didn't expect people to take is so literally and actually believe I was suggested v0. But good to know. I'm locking this conversation for maintainers as we've identified, the problem, a work around and we'll be going from there.

joshuaellis commented 3 years ago

this has been released in v6.2.3-beta.1 if you could test it @Xapu1337 that would be great!