Closed naftis closed 2 days ago
Is it OK to install tsx instead of ts-node ? I got tired of esm-module issues with ts-node and tsx worked out of the box.
I think it is. Only thing it affects really is the sizes of our docker images. We need to find a solution that works for all packages
I tried again without tsx
:
first you get TypeError: Unknown file extension ".ts" for /root/Projects/opencrvs-core/packages/migration/src/reindex-search.ts
with our ts-node version, solution is removing "type": "module"
from the package.json. Then I got:
@opencrvs/migration: ERROR: Unexpected token 'export' /root/Projects/opencrvs-core/packages/migration/build/dist/src/migrate-mongo-config-performance.js:25
@opencrvs/migration: export default config;
@opencrvs/migration: ^^^^^^
@opencrvs/migration: SyntaxError: Unexpected token 'export'
Installed latest ts-node. Added "type": "module"
back. Migrations now work.
$ node --loader ts-node/esm src/reindex-search.ts
(node:21468) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("ts-node/esm", pathToFileURL("./"));'
(Use `node --trace-warnings ...` to show where the warning was created)
Reindexing search...
...done reindexing search with job id 52bd21fa-1acd-40b3-a117-29f30ae7ded8
The deprecation warning here doesn't offer a pretty solution to get rid of it, but at least it works. It doesn't reduce the Docker image size though as our other ts-node versions are older.
Reinstall tsx
$ tsx src/reindex-search.ts
Reindexing search...
...done reindexing search with job id 1cf41ebb-84dc-42bc-ac66-66bac01b5655
Done in 1.38s.
I tested this with Mac. Not getting the error which leads us to use the ipv4-first fix ✅
7240
New dependencies introduced
tsx
. Node.js enhanced with esbuild to run TypeScript & ESM files. I had issues runningts-node
within migrations andtsx
was a drop-in replacement.