N
Nuxt5w ago
Devin

Error when deploying nuxt using bun and node 20.

Hello, i have a few errors deploying my nuxt app to an ubuntu server ive setup. The issue is when running the raw output file, i get the following error:
[nuxt] [request error] [unhandled] [500] Cannot find package '/home/vm/vzweb2/.output/server/node_modules/@unhead/shared/index.js' imported from /home/vm/vzweb2/.output/server/chunks/routes/renderer.mjs
at legacyMainResolve (node:internal/modules/esm/resolve:215:26)
at packageResolve (node:internal/modules/esm/resolve:841:14)
at moduleResolve (node:internal/modules/esm/resolve:927:18)
at defaultResolve (node:internal/modules/esm/resolve:1169:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:542:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:510:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:239:38)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:96:40)
at link (node:internal/modules/esm/module_job:95:36)
[nuxt] [request error] [unhandled] [500] Cannot find package '/home/vm/vzweb2/.output/server/node_modules/@unhead/shared/index.js' imported from /home/vm/vzweb2/.output/server/chunks/routes/renderer.mjs
at legacyMainResolve (node:internal/modules/esm/resolve:215:26)
at packageResolve (node:internal/modules/esm/resolve:841:14)
at moduleResolve (node:internal/modules/esm/resolve:927:18)
at defaultResolve (node:internal/modules/esm/resolve:1169:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:542:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:510:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:239:38)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:96:40)
at link (node:internal/modules/esm/module_job:95:36)
Ive got this kind of working by going into the /server folder and dthen deleting the node_modules and reinstalling them. The folder has run successfully on my macbook when running it from node, but it may have some other preinstalled stuff making it work.
4 Replies
kapa.ai
kapa.ai5w ago
Hi @Devin. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the error message you've provided, it seems you're encountering an issue with package resolution when deploying your Nuxt application. This is likely related to how Node.js is resolving ES modules in your production environment. Let's address this issue step by step: 1. The error suggests that Node.js cannot find the @unhead/shared package. This is often due to differences in how dependencies are resolved in development versus production environments. 2. Your workaround of deleting and reinstalling node_modules in the .output/server directory is a temporary fix, but it's not the ideal solution for a production deployment. To properly address this issue, consider the following approaches: 1. Ensure you're using a compatible Node.js version. Nuxt 3 recommends using Node.js 16.x or later. You mentioned using Node 20, which should be compatible, but it's worth double-checking. 2. Try adding the problematic package to the build.transpile config in your nuxt.config.js file. This tells Nuxt to include the package in the bundle:
export default defineNuxtConfig({
build: {
transpile: ['@unhead/shared']
}
})

export default defineNuxtConfig({
build: {
transpile: ['@unhead/shared']
}
})

Nuxt Documentation: Transpiling Libraries (https://nuxt.com/docs/guide/concepts/esm#transpiling-libraries) 3. If the issue persists, you might need to manually alias the library to its CommonJS version:
export default defineNuxtConfig({
alias: {
'@unhead/shared': '@unhead/shared/dist/index.cjs'
}
})

export default defineNuxtConfig({
alias: {
'@unhead/shared': '@unhead/shared/dist/index.cjs'
}
})

Nuxt Documentation: Aliasing Libraries (https://nuxt.com/docs/guide/concepts/esm#aliasing-libraries) 4. Ensure that your package.json doesn't have any conflicting version requirements for the @unhead/shared package. 5. When deploying, make sure you're running nuxt build before attempting to start the server. This ensures that all necessary files are generated and bundled correctly. 6. Instead of manually modifying the .output directory, it's better to rebuild the project and redeploy the entire .output directory. If these steps don't resolve the issue, you might want to check if there are any specific requirements or known issues with running Nuxt on Bun. As Bun is a relatively new JavaScript runtime, there might be compatibility issues that haven't been fully addressed yet. Remember, when deploying a Nuxt application, it's generally recommended to use the built-in deployment features or follow the official deployment guides to avoid such issues Nuxt Documentation: Deployment (https://nuxt.com/docs/getting-started/deployment). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5w ago
<@276016956245540864> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Devin
DevinOP5w ago
As it turned out, cyberduck did not upload all files, so ive zipped, uploaded and unzipped it. It is now working
Want results from more Discord servers?
Add your server