-
Notifications
You must be signed in to change notification settings - Fork 119
Error: Cannot find module 'three' #168
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
Comments
Can confirm this is still an issue. Dependencies ( "dependencies": {
"@react-three/drei": "^9.47.1",
"@react-three/fiber": "^8.9.1",
"@react-three/postprocessing": "^2.7.0",
"next": "13.0.7",
"postprocessing": "^6.29.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"three": "^0.146.0"
} Component code: 'use client';
import { GradientTexture } from '@react-three/drei';
import { Canvas } from '@react-three/fiber';
import { Bloom, DepthOfField, EffectComposer, Noise } from '@react-three/postprocessing';
import { ReactElement, useRef } from 'react';
import { DoubleSide, Mesh } from 'three';
interface Props {
width: number;
height: number;
segments?: number;
}
export const Gradient = ({ width, height, segments = 8 }: Props): ReactElement => {
const colors = ['#ff00ff', '#ff0000', '#ffffff', '#ffff00', '#00ff00', '#00ffff', '#0000ff'];
const stops = colors.map((_, i) => i / colors.length);
const mesh = useRef<Mesh>(null!);
return (
<Canvas>
<ambientLight intensity={1000} />
<mesh ref={mesh} scale={[1, 1, 1]} position={[0, 0, 0]}>
<planeGeometry args={[height, width, segments, segments]} />
<meshBasicMaterial side={DoubleSide}>
<GradientTexture stops={stops} colors={colors} />
</meshBasicMaterial>
</mesh>
<EffectComposer multisampling={0} disableNormalPass={true}>
<DepthOfField focusDistance={0.5} focalLength={0.1} bokehScale={2} height={700} />
<Bloom luminanceThreshold={0} luminanceSmoothing={0.1} height={300} opacity={3} />
<Noise opacity={0.1} />
</EffectComposer>
</Canvas>
);
};
export default Gradient; Stack trace ( > [email protected] dev /home/drew/code/test
> next dev
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info - Loaded env from /home/drew/code/test/.env.local
info - Loaded env from /home/drew/code/test/.env
warn - You have enabled experimental feature (appDir) in next.config.js.
warn - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.
info - Thank you for testing `appDir` please leave your feedback at https://nextjs.link/app-feedback
event - compiled client and server successfully in 642 ms (234 modules)
wait - compiling /page (client and server)...
warn - ./node_modules/.pnpm/[email protected][email protected]/node_modules/postprocessing/build/postprocessing.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
./node_modules/.pnpm/[email protected][email protected]/node_modules/postprocessing/build/postprocessing.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
Error: Cannot find module 'three'
at webpackEmptyContext (/home/drew/code/test/.next/server/app/page.js:22:10)
at eval (webpack-internal:///(sc_client)/./node_modules/.pnpm/[email protected][email protected]/node_modules/postprocessing/build/postprocessing.js:168:24)
at eval (webpack-internal:///(sc_client)/./node_modules/.pnpm/[email protected][email protected]/node_modules/postprocessing/build/postprocessing.js:9554:3)
at (sc_client)/./node_modules/.pnpm/[email protected][email protected]/node_modules/postprocessing/build/postprocessing.js (/home/drew/code/test/.next/server/app/page.js:8362:1)
at __webpack_require__ (/home/drew/code/test/.next/server/webpack-runtime.js:33:43)
at eval (webpack-internal:///(sc_client)/./node_modules/.pnpm/@[email protected]_aj5kj473hsgheg4miwvuwybosy/node_modules/@react-three/postprocessing/dist/index.cjs:5:22)
at (sc_client)/./node_modules/.pnpm/@[email protected]_aj5kj473hsgheg4miwvuwybosy/node_modules/@react-three/postprocessing/dist/index.cjs (/home/drew/code/test/.next/server/app/page.js:8794:1)
at __webpack_require__ (/home/drew/code/test/.next/server/webpack-runtime.js:33:43)
at eval (webpack-internal:///(sc_client)/./components/aurora/aurora.component.tsx:10:85)
at (sc_client)/./components/aurora/aurora.component.tsx (/home/drew/code/test/.next/server/app/page.js:6859:1)
at __webpack_require__ (/home/drew/code/test/.next/server/webpack-runtime.js:33:43)
at eval (webpack-internal:///(sc_client)/./components/client.ts:21:82)
at (sc_client)/./components/client.ts (/home/drew/code/test/.next/server/app/page.js:6892:1)
at __webpack_require__ (/home/drew/code/test/.next/server/webpack-runtime.js:33:43)
at eval (webpack-internal:///(sc_client)/./views/gallery/gallery.view.tsx:8:75)
at (sc_client)/./views/gallery/gallery.view.tsx (/home/drew/code/test/.next/server/app/page.js:8223:1)
at __webpack_require__ (/home/drew/code/test/.next/server/webpack-runtime.js:33:43)
at eval (webpack-internal:///(sc_client)/./views/client.ts:8:79)
at (sc_client)/./views/client.ts (/home/drew/code/test/.next/server/app/page.js:8201:1)
at __webpack_require__ (/home/drew/code/test/.next/server/webpack-runtime.js:33:43)
at requireModule (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-server-dom-webpack/client.js:142:32)
at initializeModuleChunk (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-server-dom-webpack/client.js:427:19)
at readChunk (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-server-dom-webpack/client.js:252:7)
at renderLazyComponent (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8043:19)
at renderElement (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8155:11)
at renderNodeDestructiveImpl (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8232:11)
at renderNodeDestructive (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8204:14)
at renderNode (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8388:12)
at renderChildrenArray (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8340:7)
at renderNodeDestructiveImpl (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8269:7)
at renderNodeDestructive (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8204:14)
at renderNode (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8388:12)
at renderChildrenArray (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8340:7)
at renderNodeDestructiveImpl (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8269:7)
at renderNodeDestructive (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8204:14)
at renderContextProvider (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8029:3)
at renderElement (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8143:11)
at renderNodeDestructiveImpl (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8232:11)
at renderNodeDestructive (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8204:14)
at finishClassComponent (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:7786:3)
at renderClassComponent (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:7794:3)
at renderElement (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8062:7)
at renderNodeDestructiveImpl (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8232:11)
at renderNodeDestructive (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8204:14)
at renderIndeterminateComponent (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:7884:7)
at renderElement (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8065:7)
at renderNodeDestructiveImpl (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8232:11)
at renderNodeDestructive (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:8204:14)
at finishClassComponent (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:7786:3)
at renderClassComponent (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js:7794:3) {
code: 'MODULE_NOT_FOUND'
} Stack trace ( > [email protected] build /home/drew/code/test
> next build
info - Loaded env from /home/drew/code/test/.env.local
info - Loaded env from /home/drew/code/test/.env
warn - You have enabled experimental feature (appDir) in next.config.js.
warn - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.
info - Thank you for testing `appDir` please leave your feedback at https://nextjs.link/app-feedback
info - Creating an optimized production build
warn - Compiled with warnings
./node_modules/.pnpm/[email protected][email protected]/node_modules/postprocessing/build/postprocessing.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
Import trace for requested module:
./node_modules/.pnpm/[email protected][email protected]/node_modules/postprocessing/build/postprocessing.js
./node_modules/.pnpm/@[email protected]_aj5kj473hsgheg4miwvuwybosy/node_modules/@react-three/postprocessing/dist/index.cjs
./components/aurora/aurora.component.tsx
./components/client.ts
./node_modules/.pnpm/[email protected][email protected]/node_modules/postprocessing/build/postprocessing.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
Import trace for requested module:
./node_modules/.pnpm/[email protected][email protected]/node_modules/postprocessing/build/postprocessing.js
./node_modules/.pnpm/@[email protected]_aj5kj473hsgheg4miwvuwybosy/node_modules/@react-three/postprocessing/dist/index.cjs
./components/aurora/aurora.component.tsx
./components/client.ts
info - Linting and checking validity of types
info - Collecting page data
[= ] info - Generating static pages (2/3)Error: Cannot find module 'three'
at webpackEmptyContext (/home/drew/code/test/.next/server/app/page.js:11:10)
at /home/drew/code/test/.next/server/chunks/11.js:68407:24
at 61814 (/home/drew/code/test/.next/server/chunks/11.js:77793:3)
at __webpack_require__ (/home/drew/code/test/.next/server/webpack-runtime.js:25:43)
at 54819 (/home/drew/code/test/.next/server/chunks/11.js:85748:22)
at __webpack_require__ (/home/drew/code/test/.next/server/webpack-runtime.js:25:43)
at 90279 (/home/drew/code/test/.next/server/app/page.js:44592:12)
at __webpack_require__ (/home/drew/code/test/.next/server/webpack-runtime.js:25:43)
at 78996 (/home/drew/code/test/.next/server/app/page.js:46410:14)
at __webpack_require__ (/home/drew/code/test/.next/server/webpack-runtime.js:25:43) {
code: 'MODULE_NOT_FOUND'
}
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Cannot find module 'three'
at webpackEmptyContext (/home/drew/code/test/.next/server/app/page.js:11:10)
at /home/drew/code/test/.next/server/chunks/11.js:68407:24
at 61814 (/home/drew/code/test/.next/server/chunks/11.js:77793:3)
at __webpack_require__ (/home/drew/code/test/.next/server/webpack-runtime.js:25:43)
at 54819 (/home/drew/code/test/.next/server/chunks/11.js:85748:22)
at __webpack_require__ (/home/drew/code/test/.next/server/webpack-runtime.js:25:43)
at 90279 (/home/drew/code/test/.next/server/app/page.js:44592:12)
at __webpack_require__ (/home/drew/code/test/.next/server/webpack-runtime.js:25:43)
at 78996 (/home/drew/code/test/.next/server/app/page.js:46410:14)
at __webpack_require__ (/home/drew/code/test/.next/server/webpack-runtime.js:25:43)
info - Generating static pages (3/3)
> Build error occurred
Error: Export encountered errors on following paths:
/page: /
at /home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/export/index.js:409:19
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Span.traceAsyncFn (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/trace/trace.js:79:20)
at async /home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/build/index.js:1345:21
at async Span.traceAsyncFn (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/trace/trace.js:79:20)
at async /home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/build/index.js:1205:17
at async Span.traceAsyncFn (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/trace/trace.js:79:20)
at async Object.build [as default] (/home/drew/code/test/node_modules/.pnpm/[email protected]_a35dlepzvml2hpheugyyhyekyi/node_modules/next/dist/build/index.js:66:29)
ELIFECYCLE Command failed with exit code 1. Despite the errors, the app seems to run fine during |
@drewxs My situation is exactly the same as yours. |
@z-dmgy Switching my application over back to using the Since the |
@drewxs It seems that this is the problem. I decided to switch back. Thank you for sharing. |
btw if still not opened, worth opening an issue on next js repo instead. |
@talentlessguy I will. |
is there a solution now? |
Same issue here, what gives? |
This is a problem with the app directory. At present, there is no solution. You can only return to the pages directory. |
If this is "not an issue" because app directory is not production ready, why is the "official starter" for react three fiber using app directory? |
Too bad this issue is closed. |
Update: There's a PR in the works that fixes this issue: #180. If you need it earlier, install from branch (or fork and link): npm i pmndrs/react-postprocessing#react-18-last-pp-last-three # npm
yarn add pmndrs/react-postprocessing#react-18-last-pp-last-three # yarn
pnpm i pmndrs/react-postprocessing#react-18-last-pp-last-three #pnpm Exhaustive testing in progress, but I've verified it builds using the r3f starter / postprocessing demo. (Above issue does not occur) |
I used the 'use client' declaration for a component, but the issue still persists when building it. |
Was there an issue opened with next.js for this @z-dmgy ? |
I left a review since that PR was defunct in making this library ESM-only. I'd create an issue in Next.js if possible, it's not the fault of the Node ecosystem if it can't work with its resolution algorithm. |
@marklundin |
Any updates on this issue @drewxs ? I saw that #180 was merged however I am still getting this issue with my Next.js project. I'm using the app directory and version 13.4.2 for next, and I've tried changing the different versions for next, three, and postprocessing but I still get this issue. Should I just switch to using the page directory in place of the app directory? |
I can only guess that the app dir is using a compiler which doesn't like wrapped |
Hey @CodyJasonBennett I appreciate the quick response. Sorry, but exactly how would I do that? Would I only lazy load in the library or would I have to wrap the whole component in a wrapper with SSR disabled? For context, And this is what's printed in the terminal:
|
Hi @CodyJasonBennett, just tried the solution you proposed, no success, seems like PostProcessing is just returning Here is my code snippet, it's inside a client component: // import @react-three/postprocessing library via next/dynamic and disable SSR
const PostProcessing = dynamic(
() =>
import('@react-three/postprocessing').then(mod => ({
default: mod,
})),
{
ssr: false,
}
); Console warning: nextjs: 13.4.3 |
Hey @far0s! I had also tried the lazy-loading solution to no avail, however I was able to find a work-around: I put a |
@0xIchigo oh I should have made it clearer but yeah I also have |
Also running into this issue, and like @far0s I have 'use client' and dynamic load doesn't work (my model ends up being "meshnormal" colored). Perhaps its just not working for the DepthOfField effect, so I will update when I know more. |
I successfully went around this issue by importing dynamically a parent component.
|
Thanks. Work for me to. But i still get this message : |
This wasnt working for me as well, but fixed using
|
For anyone still encountering this issue, see the above workarounds or https://npmjs.com/umd-compat-loader, but I'd continue this in Next.js since it's not supporting UMD builds with wrapped |
Using @react-three/postprocessing in next js 13 will cause an error to occur,
The text was updated successfully, but these errors were encountered: