Hey, thanks all for trying. My bad, I forgot to post my vite.config.js
and I’ve since managed to repro and narrow the problem to dynamic imports statements. My files are a mess, cos its a sandbox. To recreate on your end, just add into code alr in the doc.
- add a dynamic import statement using
switch
. In my main.js
, its
let v = 0;
switch(v){
case 0:
import("./dynImp1").then(out=>{}).catch(err=>{
console.log("import file error:"+err);
})
break;
case 1:
import("./dynImp2").then(out=>{}).catch(err=>{
console.log("import file error:"+err);
})
break;
}
- make 2 identical
dynImp
files and let your last import statement be import "@babylonjs/core/Meshes/thinInstanceMesh";
- vite build. I built as lib into
./dist
folder, so my vite.config.js
is
import { defineConfig } from 'vite';
import path from 'path';
export default defineConfig({
mode:'development',
build: {
lib: {
entry: "main.js",
formats: ['es'],
fileName: "entry", // becomes entry.es.js
},
// outDir can potentially erase existing assets if wrong dir is set, beware!
outDir:"dist",
manifest: true,
}
})
- You should get a manifest result similar to below.
{
"main.js": {
"file": "entry.es.js",
"src": "main.js",
"isEntry": true,
"imports": [
"_main.js"
]
},
"_main.js": {
"file": "main.js",
"dynamicImports": [
"dynImp1.js",
"dynImp2.js"
]
},
"dynImp1.js": {
"file": "dynImp1.js",
"src": "dynImp1.js",
"isDynamicEntry": true,
"imports": [
"_main.js",
"_thinInstanceMesh.js"
]
},
"_thinInstanceMesh.js": {
"file": "thinInstanceMesh.js",
"imports": [
"_main.js"
]
},
"dynImp2.js": {
"file": "dynImp2.js",
"src": "dynImp2.js",
"isDynamicEntry": true,
"imports": [
"_main.js",
"_thinInstanceMesh.js"
]
}
}
If you have other import statements in dynImp
, just comment out thinInstanceMesh's
and rebuild. The dangling file now shows whatever is the last import. At this point I dunno if the problem is with bjs or vite atm but its consistent and reproducible as far as using switch
is concerned. Hmm, maybe I should just revert to if-else
for now…shrugs