#ERROR [ExceptionsHandler] path must be absolute or specify root to res.sendFile

22 messages · Page 1 of 1 (latest)

primal spindle
#

I am getting this error when I try to start nestjs application. I don't see any endpoint where res.sendFile is used. I also removed all '__dirname' from configs. Can someone help me?

reef lintel
#

Can you show the full error?

primal spindle
#

[Nest] 15739 - 08/02/2023, 20:02:04 ERROR [ExceptionsHandler] path must be absolute or specify root to res.sendFile
TypeError: path must be absolute or specify root to res.sendFile
at ServerResponse.sendFile (path-to-project/node_modules/express/lib/response.js:441:11)
at renderFn (path-to-project/node_modules/@nestjs/serve-static/dist/loaders/express.loader.js:32:25)
at Layer.handle [as handle_request] (path-to-project/node_modules/express/lib/router/layer.js:95:5)
at next (path-to-project/node_modules/express/lib/router/route.js:144:13)
at Route.dispatch (path-to-project/node_modules/express/lib/router/route.js:114:3)
at Layer.handle [as handle_request] (path-to-project/node_modules/express/lib/router/layer.js:95:5)
at path-to-project/node_modules/express/lib/router/index.js:284:15
at param (path-to-project/node_modules/express/lib/router/index.js:365:14)
at param (path-to-project/node_modules/express/lib/router/index.js:376:14)
at Function.process_params (path-to-project/node_modules/express/lib/router/index.js:421:3)

#

where path-to-project is my local directory where the project is saved

reef lintel
#

Ah okay, this comes from the ServeStatic module. How do you configure that?

primal spindle
#

like in docs,

    rootPath: join(__dirname, '..' ,'static'),
}), ```
but I removed __dirname for testing because I thought that that was the issue
#

the error is the same if I moved it back

#

but I think that this worked before (this logic was in the branch on which I didn't work at least a month)

reef lintel
#

Hmm, interesting. I can only guess that a root option is missing

primal spindle
#

where can I configure that?

reef lintel
#

Inside the forRoot you can specify rootPath

primal spindle
#

you mean in this serveStaticModule configuration or somewhere else?
because I did that (see above)

reef lintel
#

Oh, shoot, you do have that 😅 I'm going between too many things. Hmm, that seems strange.

#

Would you be able to provide a repository that shows this?

primal spindle
#

oh XD my fail

#

I had two imports of ServeStaticModule

#

it seems that I took both on merge or something like that

#

and other was without __dirname 😄

#

that was the issue

#

sry for wasting your time

reef lintel
#

Oh, yeah, that would be an issue. Generally speaking .forRoot() modules should only be imported once

primal spindle
#

and thank's anyway for quick response 😄