'npm binary using ts-node causes errors when invoked using npm i -g or npx
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 -gto install globally, when the binary is called which in turn callsts-nodeI get errors for all the missing types declared indevDependenciesof the module containing the binary, sincedevDependenciesaren'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
npxcauses module related errors since I'm trying to useimportsyntax 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?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
