donalffons / opencascade.js

Port of the OpenCascade CAD library to JavaScript and WebAssembly via Emscripten.
https://ocjs.org/
GNU Lesser General Public License v2.1
582 stars 85 forks source link

How to config opencascade.js in next.js? #263

Open Flyingbeanss opened 8 months ago

Flyingbeanss commented 8 months ago

I consulted the configuration tutorial in here.But when I tried to import it, something went wrong.

My code

import initOpenCascade from "opencascade.js";

initOpenCascade().then(oc => {
  // Check out the examples on how to use this library!
});

Error image

Maybe there is something wrong in the next.config.js? My config

/** @type {import('next').NextConfig} */

module.exports = {
    transpilePackages: ['three'],
    webpack: (config, { isServer }) => {
        config.module.rules.push({
            test: /\.wasm$/,
            type: "javascript/auto",
            loader: "file-loader"
        });
        config.resolve.fallback = {
            ...config.resolve.fallback,
            fs: false,
            perf_hooks: false,
            os: false,
            worker_threads: false,
            crypto: false,
            stream: false,
        };

        return config;
    },
}

Can anyone help me? Thanks :).

Flyingbeanss commented 8 months ago

I copy the config of config-overrides.js into the next.config.js, it worked! But I don't know why. Shouldn't next.js use webpack instead of create-react-app?