-
Notifications
You must be signed in to change notification settings - Fork 639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage with latest Next.js (9.3) #2
Comments
that's odd, don't even know what that means. the published /dist/index.js is a module, no? |
I'm still trying to understand the message myself :) My guess at this point: Next.js tries to run server-side and fails somehow. I'm sure there's an explanation / actual solution for this. |
@vieko I had exactly the same problem and made a question on spectrum and twitter. The problem is that Next.js uses CommonJS modules on server, so it cannot understand ESM modules. Another solution is importing dynamically, like import dynamic from 'next/dynamic'
const Cube = dynamic(() => import('../components/Cube')) |
@talentlessguy I could not get it to work with a dynamic import (saw your post on spectrum). I think this is because the OrbitControls component included in drei, references bits in three. |
hey, just got bit by this as well. looks like the issue isn't occurring in drei proper -- the cjs version has correctly been transpiled to so for example, when i try to use imo this is... kind of three's fault for having a really janky build configuration. it's not ideal for tree-shaking, but short of having a rollup plugin rewrite import statement paths based on whether the output target is cjs or esm, maybe a good rule of thumb would be for library code like drei to use the cjs versions of three modules? |
oh wait -- i'm looking a bit more closely at three and i guess there's no cjs version of the examples code... your options are es modules or a version that patches the |
ahh, that makes sense now. yes it's kind of sad. i have made an issue for this once and it got shot down. examples/jsm breaks node resolution by digging directly into the three source with relative ../../../ paths. even crazier, in a cjs env it loads two threejs versions side-by-side because of it, they're overlapping, and it breaks some of their controls and primitives, rectAreaLights for instance. i think someone should open an issue there to make them aware that their build breaks node and ssr. |
I got this working using
|
Hey, @MichaelWheldon 's solution works for me for the most part, but I'm running into that "only after the second render" issue while using First Person Controls. I guess this isn't really a drei issue specifically, but I'd figure I'd ask here. It seems the Controls are being loaded but are extremely choppy / unresponsive until the second render. Disabling SSR with |
fwiw something like you have to explicitly disable ssr for a dynamic import, ie. i haven't come back to drei/three specifically, but i'm currently working with a different canvas application where this fixed all my issues. for three, i think a combination of transpiling modules with as i've noted in this issue comment, one simple technique is just to move your entire application root into a dynamic import. (this also saves you from having to write any conditional |
Thanks for that, @lostfictions . Doesn't fix this unresponsive FirstPersonControls issue unfortunately, but this is useful in general. |
I opened a PR to improve the next.js with-three example, please refer to that and if you can contribute 👍 |
Hey everyone! I am running into this issue and can't seem to figure out a fix. I have followed @gsimone's approach to use If I import const OrbitControls = dynamic(() => import('drei').then((mod) => mod.OrbitControls), { ssr: false }) ...which is not the cleanest way to import the components, especially as I am using a couple of other components from For reference, I am using Any ideas what I am doing wrong? You can see the code here https://github.com/MehediH/m3tamorphosis |
This is a known error currently & we're working on a fix, you can track it here #233 |
Aha! Apologies should have looked at the |
FWIW: Next.js kept complaining with
cannot use import statement outside a module
. I had to include three and drei in the transpile modules array to get OrbitControls to work:next.config.js
const withTM = require('next-transpile-modules')(['three', 'drei'])
module.exports =withTM()
Hope this helps someone else.
The text was updated successfully, but these errors were encountered: