Skip to content

flolu/ocjs-next-custom-build

Repository files navigation


Next.js + Opencascade.js Issue

Custom Opencascade.js build with Next.js issue

Requirements

  • Linux
  • Node.js + NPM

Reproduce issue

  • npm install, install dependencies
  • docker pull donalffons/opencascade.js, pull the opencascade.js Docker image
  • 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, start development server on http://localhost:3000
  • Throws error: TypeError: Cannot read properties of undefined (reading 'buffer')

Workaround

  • 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}) to initOpenCascade() in src/OCJSViewport.tsx
  • rm -rf .next, clear next cache
  • npm run dev, start development server on http://localhost:3000
  • Works just fine!

Notes

About

Error when using OpenCascade.js custom build with Next.js

Topics

Resources

Stars

Watchers

Forks