Reputation: 141
I am using a Postgres client as a dependency in my simple node js server. I noticed that this dependency has built and published itself as .ts
files, instead of .js
files. Is that a norm/good-practice? I've usually seen libraries being packages as vanilla js files and (optionally) declaring their types in .d.ts
files.
Currently, I have to use allowTsInNodeModules
in my webpack.config.ts to use this dependency, and I get the following error without using this flag:
ERROR in ./node_modules/pgeon/postgres-client.ts
Module build failed (from ./node_modules/ts-loader/index.js):
Error: TypeScript emitted no output for /home/dinika/src/expenses-server-node/node_modules/pgeon/postgres-client.ts. By default, ts-loader will not compile .ts files in node_modules.
You should not need to recompile .ts files there, but if you really want to, use the allowTsInNodeModules option.
Upvotes: 1
Views: 1388
Reputation: 1887
This is not a best practice nor the norm. The developer of that library should likely read how to publish TypeScript packages.
A summary is they should have a main
and types
key in their package.json
and be compiling their TypeScript to declarations and JavaScript (*.d.ts
and *.js
files).
Upvotes: 1