N
Nuxt3mo ago
oussamalkd

Cannot find module '@vue/shared' when running node .output/server/index.mjs after Nuxt 4 build

Hi 👋 I built my Nuxt 4 app using: nuxi build Then I tried to run it for testing with: node .output/server/index.mjs but I get:
Error: Cannot find module '@vue/shared'
Require stack:
- .output/server/node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js
Error: Cannot find module '@vue/shared'
Require stack:
- .output/server/node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js
I didn’t include the node_modules folder because according to the Nuxt docs and a video from @danielroe it should be enough to deploy only the .output folder.
4 Replies
kapa.ai
kapa.ai3mo ago
Hi @oussamalkd. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- You're correct that, according to Nuxt 4 documentation, after running nuxi build, you should be able to deploy and run your app using only the .output directory, without needing to include node_modules—the output is meant to be self-contained for production use:
When running nuxi build with the Node server preset, the result will be an entry point that launches a ready-to-run Node server.
>
node .output/server/index.mjs
node .output/server/index.mjs
>
This will launch your production Nuxt server that listens on port 3000 by default.
>
Docs > 4.x > Getting-started > Deployment
However, the error you're seeing:
Error: Cannot find module '@vue/shared'
Require stack:
- .output/server/node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js
Error: Cannot find module '@vue/shared'
Require stack:
- .output/server/node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js
suggests that a dependency (@vue/shared) is missing from the .output directory. This is not expected behavior if the build process completed successfully, as all required dependencies should be bundled or copied into .output/server/node_modules by Nitro during the build. Possible Causes - Build Incomplete or Misconfigured: If the build did not complete successfully, or if there is a misconfiguration, some dependencies might not be bundled into .output. - Manual Changes or Custom Nitro Preset: If you have customized the Nitro preset or altered the build process, it could affect which dependencies are included. - Corrupted or Incomplete Project State: Sometimes, issues with the local environment or corrupted caches can cause incomplete builds. Troubleshooting Steps 1. Clean and Rebuild: - Delete .output, .nuxt, and any build caches. - Run nuxi build again and check for any warnings or errors during the build. 2. Check for Externalized Dependencies: - By default, Nitro should bundle all necessary dependencies. If you have custom Nitro config, ensure you are not externalizing dependencies that are required at runtime. 3. Compare with a Fresh Project: - As seen in a similar issue, creating a new Nuxt project and carefully copying your files over can sometimes resolve mysterious build issues if something is wrong with the project setup or configuration. In that case, the .output folder was empty until the project was recreated from scratch, after which it worked as expected Nuxt3 build .output folder remains empty, nothing copied from .nuxt. 4. Check Node Version Compatibility: - Ensure your Node.js version matches the one recommended by Nuxt 4 (Node 18+ is generally safe). Summary You are correct that you should not need to include node_modules for deployment. The error indicates a build or configuration issue. Try cleaning and rebuilding your project, and if the problem persists, consider recreating your project as described above. If you have custom Nitro or build configuration, review it to ensure all dependencies are bundled. If after these steps the issue remains, the knowledge sources do not provide a more specific solution for this exact error in Nuxt 4. If you can share your nuxt.config and any custom Nitro configuration, it may help further diagnose the problem. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@709132630162931742> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
danielroe
danielroe3mo ago
please open an issue with a reproduction 🙏
oussamalkd
oussamalkdOP3mo ago
@danielroe https://github.com/nuxt/nuxt/issues/33311 more details and notes there Thanks 🙏
GitHub
Cannot find module '@vue/shared' when running node .output/server/i...
Environment Operating System: Windows_NT Node Version: v20.19.0 Nuxt Version: 4.1.2 CLI Version: 3.28.0 Nitro Version: 2.12.6 Package Manager: yarn@1.22.19 Builder: - User Config: devtools, compati...

Did you find this page helpful?