I have a React project, and it includes talking to an API.
I have a module defined in the project that abstracts away the api access.
So for example it has methods like addFoo
and getFoos
. I would like to use this module from a script that I would like to run directly on the command line. The purpose of the script is to load a bunch of data into a database via the api.
When I use plain .js
, it seems to be fairly easy to just run > node path/to/file
. The relative import paths work fine.
Issue
When I use .ts
it doesn't work. It complains that it can't find the module.
Question
What's the right way to run a .ts
CLI script in a React project directly? Or is this the wrong way to do this?
Thanks !
MwamiTovi's response above was close however I additionally had to set {"module": "commonjs"}
.
ts-node -O '{"module":"commonjs"}' src/tools/foo.ts
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.