opencascade.js
opencascade.js copied to clipboard
Custom builds do not work with Next.js
Objective
I want to use ocjs-create-next-app-12 with custom builds.
Issue
But I ran into an error. This is my minimal reproduction of the issue:
-
git clone https://github.com/flolu/ocjs-next-custom-build
-
cd ocjs-next-custom-build
-
npm install
-
docker pull donalffons/opencascade.js
- Build custom JavaScript and WebAssembly code (takes a few minutes)
docker run \ --rm \ -it \ -v "$(pwd):/src" \ -u "$(id -u):$(id -g)" \ donalffons/opencascade.js \ custom-occ-build.yml
-
npm run dev
Throws error:TypeError: Cannot read properties of undefined (reading 'buffer')
when opening http://localhost:3000
Workaround
But I also found a workaround, which involves copying the build files into node_modules/opencascade.js/dist
:
- Backup default full builds
mkdir node_modules/opencascade.js/dist/backup && \ mv node_modules/opencascade.js/dist/opencascade.* node_modules/opencascade.js/dist/backup/
- Copy custom build files into
node_modules
cp customBuild.examples.d.ts ./node_modules/opencascade.js/dist/opencascade.full.d.ts && \ cp customBuild.examples.js ./node_modules/opencascade.js/dist/opencascade.full.js && \ cp customBuild.examples.wasm ./node_modules/opencascade.js/dist/opencascade.full.wasm
- Change
initOpenCascade({mainJs: opencascade, mainWasm: opencascadeWasm})
toinitOpenCascade()
insrc/OCJSViewport.tsx
-
rm -rf .next
, clear next cache -
npm run dev
, start development server on http://localhost:3000 - Works just fine!
Notes
- This is a modified version of ocjs-create-next-app-12
- I've changed the
webpack
configuration innext.config.js
- I've changed the
initOpenCascade
to use the custom build insrc/OCJSViewport.tsx