Nuxt 3.7.0 with Nitro 2.6.2 build server cause port problem when deploy on azure app service
Environment
- Operating System: Windows_NT
- Node Version: v18.17.1
- Nuxt Version: 3.7.0
- CLI Version: 3.7.2
- Nitro Version: 2.6.2
- Package Manager: [email protected]
Reproduction
using a Nuxt 3.7.0 with Nitro 2.6.2 project yarn run build and deploy to a azure app service
Describe the bug
RangeError [ERR_SOCKET_BAD_PORT]: options.port should be >= 0 and < 65536. Received \.\pipe\a52b3a22-a8b8-516c-b23f-b824dbfe0c8f.at new NodeError (node:internal/errors:393:5)at validatePort (node:internal/validators:372:11)at Server.listen (node:net:1613:5)at file:///C:/home/site/wwwroot/.output/server/chunks/nitro/node-server.mjs:5617:25at ModuleJob.run (node:internal/modules/esm/module_job:193:25)at async Promise.all (index 0)at async ESMLoader.import (node:internal/modules/esm/loader:530:24)at async importModuleDynamicallyWrapper (node:internal/vm/module:438:15)
Additional context
currently edit .output/server/server/chunks/nitro/node-server.mjs const listener = server.listen(path ? { path } : { port, host }, (err) => { to const listener = server.listen(port, host, (err) => { can fix the problem
Logs
No response
Can you please provide a reproduction? 🙏🏼
create a new project using npx nuxi@latest init nuxt3.7.0 https://github.com/annndddy/nuxt3.7.0
yarn run build and deploy the .output server.js web.config to the azure app service use browser to access the page and the server log will show Application has thrown an uncaught exception and is terminated: RangeError [ERR_SOCKET_BAD_PORT]: options.port should be >= 0 and < 65536. Received \.\pipe\25ca48bd-25d5-5ac8-b052-66e4d31687f7. at new NodeError (node:internal/errors:393:5) at validatePort (node:internal/validators:372:11) at Server.listen (node:net:1613:5) at file:///C:/home/site/wwwroot/.output/server/chunks/nitro/node-server.mjs:5499:25 at ModuleJob.run (node:internal/modules/esm/module_job:193:25) at async Promise.all (index 0) at async ESMLoader.import (node:internal/modules/esm/loader:530:24) at async importModuleDynamicallyWrapper (node:internal/vm/module:438:15)
and this is a error that happened before https://github.com/nuxt/nuxt/issues/14958 https://github.com/unjs/nitro/issues/507
@annndddy I am having the same problem on IIS server. Did you solve the problem?
@pi0 Did you solve the problem?
@tolgahanbeyazoglu currently i edit .output/server/server/chunks/nitro/node-server.mjs before deploy to fix the problem
@annndddy I will continue to change it for now, I hope nuxt offers a solution. thank you
Having the same problem on mittwald server. Instead of ports they give you a socket. How do I use this in Nuxt?
NITRO_UNIX_SOCKET=[path_of_socket] (.\pipe\25ca48bd-25d5-5ac8-b052-66e4d31687f7) solves the issue for me.
@fabianwohlfart Did you find a solution? If you found it, how to use it?
@fabianwohlfart Did you find a solution? If you found it, how to use it?
Yes. So basically you have to tell your Nuxt application that a socket is used instead of a port. You are doing this by explicitly setting the NITRO_UNIX_SOCKET env variable to the path of your socket.
@pi0 I was wondering if there is a documentation about all possible env variables in the Nuxt docs?
@tolgahanbeyazoglu @fabianwohlfart i using @fabianwohlfart idea to use the NITRO_UNIX_SOCKET by create a nitro plugin to set the value and it works now
nitroPlugins/unixsocket.ts
export default defineNitroPlugin((nitroApp) => {
process.env.NITRO_UNIX_SOCKET = process.env.PORT
})
nuxt.config.ts
export default defineNuxtConfig({
nitro: {
plugins: ['~/nitroPlugins/unixsocket.ts']
},
..
})
@annndddy Thank you, it is surprising that there is no explanation on nuxt !!
https://github.com/unjs/nitro/pull/1783/files was merged for IIS, I believe a similar approach could be used for Azure ?
@Hebilicious thank you I don't understand how to use it ?
@Hebilicious thank you I don't understand how to use it ?
You'd need to use either the plugin workaround (recommended) or a custom driver.
Hello
Does anyone know why NITRO_PORT=3001 works in .env but NITRO_UNIX_SOCKET=/tmp/my-new-nitro.sock does not?
project Nuxt 3.11.2 with Nitro 2.9.6
I need to give each user a different socket, as I am using a code-server, with the "Running Multiple code-server Instances on Different Ports" approach