WASM files from the dependencies are not copied during the build
Describe the bug
When you build the Nitro.js project which depends on tesseract.js (which in turn depends on tesseract.js-core), the wasm files are not copied from the tesseract.js-core package to the output directory.
Reproduction
Clone and build the project:
git clone https://github.com/slavafomin/nitro-wasm-issue && cd nitro-wasm-issue
npm install
DEV mode:
npm run dev
open "http://localhost:3001"
Everything should work.
Production mode:
npm run build
node ./.output/server/index.mjs
open "http://localhost:3000"
Getting error:
Aborted(Error: ENOENT: no such file or directory, open '/nitro-wasm-issue/.output/server/node_modules/tesseract.js-core/tesseract-core-simd.wasm')
failed to asynchronously prepare wasm: RuntimeError: Aborted(Error: ENOENT: no such file or directory, open '/nitro-wasm-issue/.output/server/node_modules/tesseract.js-core/tesseract-core-simd.wasm'). Build with -sASSERTIONS for more info.
Aborted(RuntimeError: Aborted(Error: ENOENT: no such file or directory, open '/nitro-wasm-issue/.output/server/node_modules/tesseract.js-core/tesseract-core-simd.wasm'). Build with -sASSERTIONS for more info.)
[uncaughtException] Error [RuntimeError]: Aborted(Error: ENOENT: no such file or directory, open '/nitro-wasm-issue/.output/server/node_modules/tesseract.js-core/tesseract-core-simd.wasm'). Build with -sASSERTIONS for more info.
at n (/nitro-wasm-issue/.output/server/node_modules/tesseract.js-core/tesseract-core-simd.js:13:225)
at Ma (/nitro-wasm-issue/.output/server/node_modules/tesseract.js-core/tesseract-core-simd.js:14:143)
at /nitro-wasm-issue/.output/server/node_modules/tesseract.js-core/tesseract-core-simd.js:14:491
WASM files are missing from the dependency:
ls -lah ./.output/server/node_modules/tesseract.js-core/*.wasm
ls: cannot access './.output/server/node_modules/tesseract.js-core/*.wasm': No such file or directory
Environment
$ node --version
v22.19.0
$ npm --version
11.6.0
$ npx nitro --version
2.12.6
I think this might be the same issue that I also have in #3582.
What might work is to add the path to externals.traceInclude:
export default defineNitroConfig({
srcDir: "server",
externals: {
traceInclude: [
'node_modules/tesseract.js-core',
],
},
})
It does seem to copy the missing stuff in the output, but unfortunately for me it did not work reliably. In my case the dependency in question is installed twice in two different versions, and in .output I get both versions in separate folders, but only one folder has the missing files included. And unfortunately it resolves to the folder without the missing files at runtime.