Basically the issue relies on the step that I run the following command to transpile+bundle my TS code to JS:
esbuild --tsconfig=./tsconfig.build.json --bundle --platform=node --outfile=dist/index.js ./src/index.ts
I have couchbase ^4.4.0
as a dependency of my project, and EVERY time I run the project after bundled, it shows this error:
/Users/joaocasarin/Desktop/job/server-code/refactoring/dist/index.js:23778
CN_ROOT = path.resolve(path.dirname(__filename), "..");
^
ReferenceError: CN_ROOT is not defined
at node_modules/couchbase/scripts/prebuilds.js (/Users/joaocasarin/Desktop/job/server-code/refactoring/dist/index.js:23778:13)
at __require (/Users/joaocasarin/Desktop/job/server-code/refactoring/dist/index.js:9:50)
at node_modules/couchbase/dist/binding.js (/Users/joaocasarin/Desktop/job/server-code/refactoring/dist/index.js:24295:7)
at __require (/Users/joaocasarin/Desktop/job/server-code/refactoring/dist/index.js:9:50)
at node_modules/couchbase/dist/couchbase.js (/Users/joaocasarin/Desktop/job/server-code/refactoring/dist/index.js:37632:37)
at __require (/Users/joaocasarin/Desktop/job/server-code/refactoring/dist/index.js:9:50)
at Object.<anonymous> (/Users/joaocasarin/Desktop/job/server-code/refactoring/dist/index.js:42232:32)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
Node.js v20.11.0
It doesn’t happen if I just transpile the TS code to JS, but due to internal decisions, we want it bundled as well, and esbuild seemed to be the fastest option so far.
What can we do to resolve this?
EDIT:
These two are the ONLY mentions of CN_ROOT
in the bundled code: