I develop an app with node.js Fastify framework (typescript, ES syntax). I decided to transpile files to CommonJS syntax to avoid incompatibilities in node environment. The app compiles from Typescript to JS successfully, but when I try to run the resulting app.cjs file, I get the following error:
backend/dist$ node app.cjs
/home/myzader/vc-app/backend/node_modules/fastify/lib/error-serializer.js:7
const { Serializer, Validator } = dependencies
^
TypeError: Cannot destructure property 'Serializer' of 'dependencies' as it is undefined.
at Object.<anonymous> (/home/myzader/vc-app/backend/node_modules/fastify/lib/error-serializer.js:7:11)
at Module._compile (node:internal/modules/cjs/loader:1368:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)
at Module.load (node:internal/modules/cjs/loader:1205:32)
at Module._load (node:internal/modules/cjs/loader:1021:12)
at Module.require (node:internal/modules/cjs/loader:1230:19)
at require (node:internal/modules/helpers:179:18)
at Object.<anonymous> (/home/myzader/vc-app/backend/node_modules/fastify/lib/error-handler.js:20:24)
at Module._compile (node:internal/modules/cjs/loader:1368:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)
tsconfig.json:
"extends": "@tsconfig/node20/tsconfig.json",
"compilerOptions": {
"target": "es6",
"module": "esnext",
"allowJs": true,
"outDir": "./dist",
"rootDir": "./",
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true,
"noEmitOnError": true,
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": false,
"resolveJsonModule": true
},
"include": [
"./**/*.ts"
],
"exclude": [
"node_modules",
"**/*.spec.ts" // Exclude test files, if applicable
]
}
.babelrc:
{
"presets": [
["@babel/preset-env", {
"modules": "commonjs"
}],
"@babel/preset-typescript"
]
}
is it related to configs? Thank you!