Mesh-BVH compilation error from Needle package

Hello,

My project was working I got continually an error about Mesh-BVH on my project since I update my project to the “@needle-tools/engine”: “^3.47.6-beta”.
I used Mesh-BVH before needle add it in its dependencies.
“three-mesh-bvh”: “^0.7.8”,

And now, this error block my entire project :
X [ERROR] No matching export in “external:three-mesh-bvh” for import “MeshBVH”

node_modules/@needle-tools/engine/lib/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js:2:9:
  2 │ import { MeshBVH } from 'three-mesh-bvh';
    ╵          ~~~~~~~

17:06:56 [vite] error while updating dependencies:
Error: Build failed with 1 error:
node_modules/@needle-tools/engine/lib/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js:2:9: ERROR: No matching export in “external:three-mesh-bvh” for import “MeshBVH”
at failureErrorWithLog (C:\Users\aeist\OneDrive\Documents\Projets\withGit2\AligneursFrancaisNeedle_WithGit\Needle\newProject\node_modules\esbuild\lib\main.js:1575:15)
at C:\Users\aeist\OneDrive\Documents\Projets\withGit2\AligneursFrancaisNeedle_WithGit\Needle\newProject\node_modules\esbuild\lib\main.js:1033:28
at runOnEndCallbacks (C:\Users\aeist\OneDrive\Documents\Projets\withGit2\AligneursFrancaisNeedle_WithGit\Needle\newProject\node_modules\esbuild\lib\main.js:1447:61)
at buildResponseToResult (C:\Users\aeist\OneDrive\Documents\Projets\withGit2\AligneursFrancaisNeedle_WithGit\Needle\newProject\node_modules\esbuild\lib\main.js:1031:7)
at C:\Users\aeist\OneDrive\Documents\Projets\withGit2\AligneursFrancaisNeedle_WithGit\Needle\newProject\node_modules\esbuild\lib\main.js:1143:14
at responseCallbacks. (C:\Users\aeist\OneDrive\Documents\Projets\withGit2\AligneursFrancaisNeedle_WithGit\Needle\newProject\node_modules\esbuild\lib\main.js:680:9)
at handleIncomingPacket (C:\Users\aeist\OneDrive\Documents\Projets\withGit2\AligneursFrancaisNeedle_WithGit\Needle\newProject\node_modules\esbuild\lib\main.js:735:9)
at Socket.readFromStdout (C:\Users\aeist\OneDrive\Documents\Projets\withGit2\AligneursFrancaisNeedle_WithGit\Needle\newProject\node_modules\esbuild\lib\main.js:656:7)
at Socket.emit (node:events:514:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)

Did somebody can help me about it ?

Hello,

I update my needle engine to 3.47.8, but I still got the same problem…

I need to resolve that quickly, if somebody can help me to resolve that.
I tried to solve it by using the vite config too, but nothing work.

Hello,

I found a “mild solution”, by replacing :
import { MeshBVH } from ‘three-mesh-bvh’;
by
import { MeshBVH } from ‘three-mesh-bvh/build/index.module.js’;

In node_modules/@needle-tools/engine/lib/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js

But it’s on local, so if I deploy it on a server, It will not work.

If a needle staff is available, please give a look if this fix is possible on this needle package.

Have a good day,

Hi, could you update Needle Engine to the latest release version?

Hello, yes, but I think I already did 3.47.8 is the last version isn’t it ?

My error appear in the vite logs, so my web page crash

In node_modules/@needle-tools/engine/lib/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js

This code doesn’t find MeshBVH
But I use it and import it in my own script and it works
It doesn’t work only in this needle package script

After updating needle to the last version available on npm website, no changes

Hi, this doesnt reproduce for me (see a quick test project - you can run npm run build:dev in the stackblitz terminal to build)

Can you compare your project with the one linked above? Did you modify the vite.config by any chance? Note that you do have a differnet mesh bvh version installed

Hello Marcel,

Thanks for you help, I changed the vite config with the exact same one than yours on your test and it works now.
My project is old so I think the vite config changed not enough by comparison with the vite config of the new needles templates.

To add an example, here the vite config I used :

import * as path from 'path';
import { defineConfig, optimizeDeps } from 'vite';
import viteCompression from 'vite-plugin-compression';
import basicSsl from '@vitejs/plugin-basic-ssl'
import react from '@vitejs/plugin-react'
import { createServer } from 'https';
import { Server } from 'ws';
import { readFileSync } from 'fs';

export default defineConfig(async ({ command }) => {

    const { needlePlugins, useGzip, loadConfig } = await import("@needle-tools/engine/plugins/vite/index.js")
    const needleConfig = await loadConfig()
    
        base: "./",
        assetsInclude: ['*'],
        plugins: [
            react(),
            needlePlugins(command, needleConfig),
            // basicSsl(),
        ],
        server: {
            port: 5173,
            https: false,
            hmr: {
                overlay: false,
                protocol: 'ws'
            },
            webSocketServer: false,
            watch: {
                awaitWriteFinish: {
                    stabilityThreshold: 500,
                    pollInterval: 1000
                },
            },
            strictPort: true,
        },
        build: {
            outDir: "./dist",
            emptyOutDir: true,
            keepNames: true,
        },
        resolve: {
            alias: {
                'three': () => {
                    const absPath = path.resolve(__dirname, 'node_modules/three');
                    return absPath;
                },
                '@needle-tools/engine': () => {
                    const absPath = path.resolve(__dirname, 'node_modules/@needle-tools/engine');
                    return absPath;
                },
                'react': () => {
                    const absPath = path.resolve(__dirname, 'node_modules/react');
                    return absPath;
                },
            }
        }
    };
});

And here the vite config I use from your example :


import { defineConfig } from 'vite';
import viteCompression from 'vite-plugin-compression';

export default defineConfig(async ({ command }) => {
    const { needlePlugins, useGzip, loadConfig } = await import("@needle-tools/engine/plugins/vite/index.js");
    const needleConfig = await loadConfig();
    return {
        base: "./",
        plugins: [
            useGzip(needleConfig) ? viteCompression({ deleteOriginFile: true }) : null,
            needlePlugins(command, needleConfig, { noPoster: true }),
        ],
        server: {
            https: false,
            proxy: { // workaround: specifying a proxy skips HTTP2 which is currently problematic in Vite since it causes session memory timeouts.
                'https://localhost:5173': 'https://localhost:5173'
            },
            strictPort: true,
            port: 5173,
        },
        build: {
            outDir: "./dist",
            emptyOutDir: true,
            keepNames: true,
        }
    }
});

Hello Marcel,

I got another error, I used the same vite config than you in my code.
It resolved the error in local, but I used it in a docker container for production with image node:18.17.1-alpine

And, I don’t know why, the error appears again, the exact same (not importing Mesh BVH in the needle component).
Which make the server crash, I resolved it temporarly by commenting the needle script : In node_modules/@needle-tools/engine/lib/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js

But I didn’t find how to resolve it and make it worked in the container.

Do you have a solution ?

Sorry for duplicate the topic, I thought it was a different one because it happens in a container and that this one was closed.

So here my vite config :

import { defineConfig } from 'vite';
import viteCompression from 'vite-plugin-compression';

export default defineConfig(async ({ command, mode }) => {
    const { needlePlugins, useGzip, loadConfig } = await import("@needle-tools/engine/plugins/vite/index.js");
    const needleConfig = await loadConfig();

    // Détermine si nous sommes en mode développement
    const isDevelopment = mode === 'development';

    return {
        base: "./",
        plugins: [
            useGzip(needleConfig) ? viteCompression({ deleteOriginFile: true }) : null,
            needlePlugins(command, needleConfig, { noPoster: true }),
        ],
        server: isDevelopment
            ? {
                  host: '0.0.0.0',
                  port: 5173,
                  https: false,
                  strictPort: true,
                  hmr: {
                      protocol: 'ws',
                      host: 'localhost',
                      port: 5173,
                  },
              }
            : undefined, // Pas de configuration du serveur en production
        build: {
            outDir: "./dist",
            emptyOutDir: true,
            keepNames: true,
        },
    };
});

Did somebody has a solution ?

Technically there’s no difference if it runs in a container - can you share your build commands and which vite version are you using?

It might be worth to try upgrading to Node 20 (instead of 18)

Okay I will try thanks

Hello,

I tried by changing the image with node 20.9.0 and it doesn’t work.

The server is on, but if I try to connect then this error appears and nothing is displayed

Please share more information about your container (see my previous reply)

Sorry,

It uses VITE v3.2.11

Here my container docker file :

# base image
FROM node:20.9.0-alpine


# set working directory
WORKDIR /app

# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH

RUN apk add bash

# install app dependencies
COPY package.json ./
RUN npm install 

# add app
COPY . ./

RUN chmod 777 -Rf /app/node_modules/
#RUN cd ./app
#RUN npm run build:production

EXPOSE 5173
EXPOSE 1107
EXPOSE 24678

# start app
CMD ["npm", "run", "start"]

I launch it with this sh script :


docker stop needlefrontend 

yes | docker system prune

docker build -t needlefrontend  . -f Dockerfile

docker run \
  --name needlefrontend \
  --network needlenetwork \
  --ip 172.20.0.5 \
  --hostname needlefrontend  \
  --restart unless-stopped \
  --dns=8.8.8.8 \
  -v ${PWD}:/app \
  -v /app/node_modules \
  -v /app/build \
  -p 5173:5173 \
  -p 1107:1107 \
  -p 24678:24678 \
  -e CHOKIDAR_USEPOLLING=true \
  -d needlefrontend 

yes | docker system prune

That’s probably why it doesnt work - vite 3 is quite old.
Please upgrade to vite: <=4.3.9

Oh ok, thanks a lot, I will try this and tell if it works

Hello,

I changed my version to vite v4.5.5 and now it works.

Thanks a lot for your help, as usual