How to fix the error when you run the script with cron?

Additional information
File upload.ts contains
console.log(process.argv);
Consider a few situations:
1. When you run the script while in the directory root/ team ts-node /root/autoinst/instAPI/bot/upload.ts

The script starts but fails with error Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i @types/node`.
Screen

5e983429f3d7e559755859.png


2. When you run the script while in the directory root/autoinst/instAPI team ts-node /root/autoinst/instAPI/bot/upload.ts
The script runs and returns
[
'/root/.nvm/versions/node/v12.14.1/bin/ts-node',
'/root/autoinst/instAPI/bot/upload.ts'
]

Everything Is OK
Screen
5e983470d1de0945548957.png


3. Run the script from directory root/ but the team
ts-node --dir /root/autoinst/instAPI/bot/ /root/autoinst/instAPI/bot/upload.ts

The result is the same as in P2. (If you run the command ts-node-s /root/autoinst/instAPI/bot/upload.ts the result is the same). The list of options ts-node attached below.
Screen
5e983544213d7232566720.png


The list of options
5e9839c9a0d57570659243.png


If you create a new cron job
*/5 7-21 * * * /root/.nvm/versions/node/v12.14.1/bin/ts-node --dir /root/autoinst/instAPI/bot/ /root/autoinst/instAPI/bot/upload.ts >> log.log


After her run in the file var/mail/root will be a letter of such content:
Subject: Cron <root@ip> /root/.nvm/versions/node/v12.14.1/bin/ts-node --dir /root/autoinst/instAPI/bot/ /root/autoinst/instAPI/bot/upload.ts >> /root/autoinst/tgBot/logs/cronTurn.log
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
Message-Id: <20200416105003.6DA211CEAC@.>
Date: Thu, 16 Apr 2020 13:50:03 +0300 (MSK)

(node:32420) ExperimentalWarning: The ESM module loader is experimental.
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /root/autoinst/instAPI/bot/upload.ts
 at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:65:15)
 at Loader.getFormat (internal/modules/esm/loader.js:110:42)
 at Loader.getModuleJob (internal/modules/esm/loader.js:241:31)
 at processTicksAndRejections (internal/process/task_queues.js:97:5)
 at Loader.import (internal/modules/esm/loader.js:175:17)


Ie the script does not run and returns an error TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"

How do I fix it?

And again. When you start with the crown, the team ts-node is not defined, so I specified the full path to the file, namely /root/.nvm/versions/node/v12.14.1/bin/ts-node
April 19th 20 at 12:19
1 answer
April 19th 20 at 12:21
Try to add

*/5 7-21 * * * cd autoinst/instAPI; /root/.nvm/versions/node/...........
nope - Justine.Simon commented on April 19th 20 at 12:24

Find more questions by tags TypeScriptThe task schedulers