Coder Social home page Coder Social logo

Comments (13)

talentlessguy avatar talentlessguy commented on June 15, 2024 3

Should work with:

"@react-three/fiber": "^6.0.1",
"@react-three/postprocessing": "^2.0.1",
"next": "^10.1.2",
"postprocessing": "^6.21.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"three": "^0.127.0"

@kyleawayan @nathanbabcock @vinkovsky @sargunv @MichalPrzybys-TomTom @marcelmusiol lmk if the issue is still present

from react-postprocessing.

ZowieTao avatar ZowieTao commented on June 15, 2024 3

In the Next.js 13 project, global server-side rendering (SSG) is enabled by default, and the component is for client-side rendering (CSR) effects and cannot be processed during server-side rendering. This can cause build errors. To fix this, you can move the code that uses the component into a client-rendered environment to ensure that it is only executed on the client side.

const DepthOfField = dynamic(
  () =>
    import("@react-three/postprocessing").then((module) => module.DepthOfField),
  {
    ssr: false,
  },
)
const EffectComposer = dynamic(
  () =>
    import("@react-three/postprocessing").then(
      (module) => module.EffectComposer,
    ),
  {
    ssr: false,
  },
)

from react-postprocessing.

sargunv avatar sargunv commented on June 15, 2024 1

I'm using CRA, not Next, but I had a similar error and was able to resolve it by adding this Babel plugin: @babel/plugin-proposal-optional-chaining. A quick look at the index.js file in the tarball shows optional chaining is being used in a couple spots.

from react-postprocessing.

kyleawayan avatar kyleawayan commented on June 15, 2024

Using code from Effects.js from https://codesandbox.io/embed/r3f-game-i2160 for now

from react-postprocessing.

nathanbabcock avatar nathanbabcock commented on June 15, 2024

I'm getting the same error

from react-postprocessing.

mfanuzzi avatar mfanuzzi commented on June 15, 2024

Fails on Gatsby as well. Presumably it's an issue with SSG; eg using window without checking for its existence.

As such, the same approach applies for other modules that do this: use Loadable Components.

This is something the developers should fix, but this works until then.

from react-postprocessing.

vinkovsky avatar vinkovsky commented on June 15, 2024

Same here

from react-postprocessing.

MichalPrzybys-TomTom avatar MichalPrzybys-TomTom commented on June 15, 2024

As suggested here webpack/webpack#10227, there is a workaround - you can add resolutions with acorn 8.x to your package.json.

from react-postprocessing.

marcelmusiol avatar marcelmusiol commented on June 15, 2024

Did anyone find a working solution for Nextjs? I tried adding adding resolutions with acorn 8.x to package.json and using the @babel/plugin-proposal-optional-chaining plugin, but no success so far.

Edit: Found a solution: vercel/next.js#20363 (comment)
Add next.config.js to the root directory and add:

module.exports = {
  future: { webpack5: true }
}

from react-postprocessing.

denkravchu avatar denkravchu commented on June 15, 2024

still the same error with nuxt js

from react-postprocessing.

drcmda avatar drcmda commented on June 15, 2024

still the same error with nuxt js

is it latest? can you go back a few versions, at least before ssr was merged? maybe it's that.

from react-postprocessing.

williaster avatar williaster commented on June 15, 2024

I still get this error with latest everything:

"@react-three/drei": "^9.17.0",
"@react-three/fiber": "^8.0.27",
"@react-three/postprocessing": "^2.4.6",
"next": "12.2.1",
"postprocessing": "^6.28.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"three": "^0.142.0"

also tried adding next-transpile-modules to transpile the build node_modules but no dice.

error - /Users/christopher-williams/dev/r3f-spaceship/node_modules/postprocessing/build/postprocessing.js:1405
      this.fragmentShader = effect_default.replace(EffectShaderSection.FRAGMENT_HEAD, shaderParts.get(EffectShaderSection.FRAGMENT_HEAD) ?? "").replace(EffectShaderSection.FRAGMENT_MAIN_UV, shaderParts.get(EffectShaderSection.FRAGMENT_MAIN_UV) ?? "").replace(EffectShaderSection.FRAGMENT_MAIN_IMAGE, shaderParts.get(EffectShaderSection.FRAGMENT_MAIN_IMAGE) ?? "");
                                                                                                                                          ^

SyntaxError: Unexpected token '?'
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/Users/christopher-williams/dev/r3f-spaceship/node_modules/@react-three/postprocessing/dist/index.cjs:5:22)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) {
  page: '/'
}

from react-postprocessing.

K-JAX avatar K-JAX commented on June 15, 2024

On the off chance this helps anybody who finds their way here - I got this error when I tried to use the code from the r3f docs page for Depth of Field not understanding that in order to use the DepthOfField component, it must be placed in the EffectComposer component as stated in the react-postprocessing README.
TLDR In other words, my fix was:

<Canvas>
    {/* The rest of your scene */}
    <EffectComposer>
        <DepthOfField />
    </EffectComposer>
</Canvas>

from react-postprocessing.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.