Open jeffersonfelixdev opened 1 year ago
After a long research, I think it's a problem with esbuild that introduces a compatibility with ESM (that uses import.meta) and CJS (that uses __dirname).
I moved to process.cwd()
to get the root dir and the path is the same across tsx (dev) and tsup (prod).
Ops! I got it!
I was building all files with target set to src folder, but tsup by default bundle files. So when I start the application, only the entrypoint file is used.
I solved it on turn off bundle option.
@jsfelix is this related to https://github.com/egoist/tsup/issues/958?
I don't understand why dirname references the folder of the file executed when building with tsup. I just can't get the current directory of the file where I call dirname :(
When I call
__dirname
in tsc or tsx its value is the current directory. But in tsup the value is the entrypoint directory.Example:
Suppose there is a project where the entry point is /home/project/src/server/index.ts:
And the file /home/project/src/modules/example.ts:
When I build from tsc or run using tsx, the result is:
But when I build from tsup the result is:
Is there a way to get same result from tsc and tsx?
Upvote & Fund