unjs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.unjs.io
MIT License
5.83k stars 492 forks source link

external tracker can fail with `EACCES: permission denied, readlink '/usr/home'` #1543

Open pi0 opened 1 year ago

pi0 commented 1 year ago

Moving from https://github.com/nuxt/nuxt/issues/15700 and https://github.com/unjs/nitro/pull/941

When the Nitro externals plugin tries to trace packages using vercel/nft, the nft box tries to read all parcels up to the filesystem root in order to find packages since we specify root as / by default.

This default is needed to support various node_modules from application layers and linked npm packages that are not within the project's workspace, root, or source directories but it makes an issue in the environments like servers with limited filesystem access.

A possible solution for such environments, is to make sure you are not using external sources or linked npm packages and set this in nitro config:

nitro.config.ts:

export default defineNitroConfig({
  externals: {
    { traceOptions: { base: process.cwd() } }
  }
})

nuxt.config.ts

export default defineNuxtConfig ({
  nitro: {
      externals: {
        { traceOptions: { base: process.cwd() } }
      }
  }
})

In order to solve this issue, we need to either fix the vercel/nft to automatically suppress such issues (maybe with a warning?) or add support for multiple node_modules search path (multiple base values to support base: string | string[].

Another (acceptable) fix in nitro without fixing upstream would be to find the most common node_modules path (modulesDir: ['/home/user/project/node_modules', '/home/package/node_modules'] to automatically set base as /home/user).

Reproduction: It is hard to make one. We might try to use stackblitz and a bash script to limit filesystem permissions not sure if possible or use a Docker container. In the meantime, it is rather an accepted current issue.

avkarenow commented 1 year ago

I tested workarounds and after a little fix of syntax it works fine:

export default defineNitroConfig({
  externals: { traceOptions: { base: process.cwd() } }
})
export default defineNuxtConfig({
  nitro: {
      externals: {
        traceOptions: { base: process.cwd() }
      }
  }
})

IF you want to reporoduce that problem you can use free account at serv00.com

pi0 commented 1 year ago

Thanks for confirming here @avkarenow. Yes, yes workaround should work as long as all your node_modules reside within process.cwd.