https://github.com/flolu/ocjs-next-custom-build
Error when using OpenCascade.js custom build with Next.js
https://github.com/flolu/ocjs-next-custom-build
nextjs opencascade
Last synced: 9 months ago
JSON representation
Error when using OpenCascade.js custom build with Next.js
- Host: GitHub
- URL: https://github.com/flolu/ocjs-next-custom-build
- Owner: flolu
- Created: 2022-07-13T10:32:08.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-07-13T11:27:59.000Z (almost 4 years ago)
- Last Synced: 2025-02-26T13:32:08.034Z (over 1 year ago)
- Topics: nextjs, opencascade
- Language: TypeScript
- Homepage: https://ocjs.org
- Size: 84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## 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`](src/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](https://github.com/donalffons/opencascade.js/tree/master/starter-templates/ocjs-create-next-app-12)
- I've changed the `webpack` configuration in [`next.config.js`](next.config.js)
- I've changed the `initOpenCascade` to use the custom build in [`src/OCJSViewport.tsx`](src/OCJSViewport.tsx)