I have a module which exposes a bin
in package.json
which points to a TypeScript file. The .ts
file has a ts-node
shebang and is executable and works well.
However, when trying to use this binary from another package, I get errors:
Using
npm i -g
to install globally, when the binary is called which in turn callsts-node
I get errors for all the missing types declared indevDependencies
of the module containing the binary, sincedevDependencies
aren't installed when installing the module from another module. I have to manually install all the devDependencies such as `npm i -g @types/lodash" which makes no sense to do.Using
npx
causes module related errors since I'm trying to useimport
syntax etc from a stand-alone ts-node call:
(node:67861) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
SyntaxError: Cannot use import statement outside a module
Is there any way to build a module which exposes a binary which is a wrapper around a ts-node script, and where that binary is actually executable through npm i -g or npx?