我正在尝试在 NextJs 中使用 React 重新创建 CodeSandbox 构建。 https://codesandbox.io/embed/r3f-sparks-sbf2i
除了一个文件“Effects.js”外,一切都对我有用 我收到错误“语法错误:无法在模块外使用导入语句”`
这是来自 Sandbox 的 react 代码
import React, { useRef, useMemo, useEffect } from 'react'
import { extend, useThree, useFrame } from 'react-three-fiber'
import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer'
import { ShaderPass } from 'three/examples/jsm/postprocessing/ShaderPass'
import { RenderPass } from 'three/examples/jsm/postprocessing/RenderPass'
import { UnrealBloomPass } from 'three/examples/jsm/postprocessing/UnrealBloomPass'
import { FilmPass } from 'three/examples/jsm/postprocessing/FilmPass'
import { GlitchPass } from './post/Glitchpass'
import { WaterPass } from './post/Waterpass'
extend({ EffectComposer, ShaderPass, RenderPass, WaterPass, UnrealBloomPass, FilmPass, GlitchPass })
export default function Effects({ down }) {
const composer = useRef()
const { scene, gl, size, camera } = useThree()
const aspect = useMemo(() => new THREE.Vector2(512, 512), [])
useEffect(() => void composer.current.setSize(size.width, size.height), [size])
useFrame(() => composer.current.render(), 1)
return (
<effectComposer ref={composer} args={[gl]}>
<renderPass attachArray="passes" scene={scene} camera={camera} />
<waterPass attachArray="passes" factor={1.5} />
<unrealBloomPass attachArray="passes" args={[aspect, 2, 1, 0]} />
<glitchPass attachArray="passes" factor={down ? 1 : 0} />
</effectComposer>
)
}