I have an expressjs api that is using typescript and after a LONG time trying to work out whats going on with my path mapping failing I figured it would be worth writing something that will help others that are struggling with a similar issue.
To be clear, this issue is unsolved for me, Vercel mention in their docs that path mapping is not supported, but I considered that as many projects are on vercel and using path mappings there must be some solution, how are react projects with SSR using path mappings, wouldn’t that be the same problem?
Perhaps there isn’t, but this can at least be a topic that exists as a final place for anyone on their search to try to resolve this problem (like I wish I had), or someone in the replies may have a solution.
For reference:
From my research, it looks like when deploying to Vercel, it will look in the /api directory for .ts or .js files and then register them as serverless functions. These files cannot have any path mappings associated (like an @src or @routes import) as it doesnt know how to interpret them, that makes sense.
I figured though, that vercel would be looking at my BUILT files (which are .js and have the path mappings already resolved to relative paths ../src ../routes etc) as I specify to build the project like normal.
But it looks like these build files are only for static assets, not for actual files to be run.
So other than compiling my files and THEN pushing them to my repo for vercel to deploy (so it creates functions from the files that have the relative paths) there doesn’t seem to be a way around this.
I don’t really want to setup some intermediary CI step to compile them just for the sake of path mappings, I just expected there to be a way for vercel to run my compiled files rather than just using the ones I push to my repo
If anyone can shed some light on this, either confirming it isn’t possible or knowing a solution, please reply
Project details: