Closed moichim closed 2 weeks ago
Hi, please, has someone managed to make workerpool run in Next.js? I tried several approaches, non of them are working...
1.
"use client"; import { useEffect, useRef } from "react"; import { Pool } from "workerpool"; const ComponentWithPool: React.FC<React.PropsWithChildren> = ({children}) => { const pool = useRef<Pool>(); useEffect( () => { import( "workerpool" ).then( result => { pool.current = result.pool(); } ); }, [] ); return <div>{children}</div> } export default ComponentWithPool;
2.
"use client"; import { useRef } from "react"; import * as workerpool from "workerpool"; import { Pool } from "workerpool"; const ComponentWithPool: React.FC<React.PropsWithChildren> = ({children}) => { const pool = useRef<Pool>( workerpool.pool() ); return <div>{children}</div> } export default ComponentWithPool;
The components above are loaded dynamically in page.tsx:
page.tsx
const ComponentWithPool = dynamic( () => import( "../components/ComponentWithPool" ), { ssr: false } );
In both cases, I get the following error:
Build Error Failed to compile Next.js (14.2.5) ../../node_modules/.pnpm/workerpool@9.1.3/node_modules/workerpool/dist/workerpool.js:49:1 Module not found: Can't resolve 'worker_threads' https://nextjs.org/docs/messages/module-not-found Import trace for requested module: ./components/App.tsx ./app/page.tsx
Have I missed something?
In fact, what I try to do is much more complex - I have a TS library using workerpool internally. But the components using it have the same issues.
I'm not sure how I can help you with this, sorry.
I'll now close this issue due to a lack of activity. I hope you've found a solution.
Hi, please, has someone managed to make workerpool run in Next.js? I tried several approaches, non of them are working...
1.
2.
The components above are loaded dynamically in
page.tsx
:In both cases, I get the following error:
Have I missed something?
In fact, what I try to do is much more complex - I have a TS library using workerpool internally. But the components using it have the same issues.