我正在从事节点快递项目。我想从终端运行节点脚本。在我的项目中,我有一些要在该脚本(MyScript.js)中调用的.ts文件。
这是MyScript.js
import get from 'lodash/get';
import every from 'lodash/every';
import UserEntity from '../../../server/models/User'; // .js file
import UserService from '../../../server/services/UserService';// .ts file
const execute = async () => {/* some code */};
execute();
我从命令行尝试像这样执行MyScript.js
node --experimental-modules src/scripts/.mjs
我遇到以下错误
(node:27608) ExperimentalWarning: The ESM module loader is experimental.
{ Error: Cannot find module ../../server/services/UserService
at search (internal/modules/esm/default_resolve.js:29:12)
at Loader.resolve [as _resolve] (internal/modules/esm/default_resolve.js:65:11)
at Loader.resolve (internal/modules/esm/loader.js:58:33)
at Loader.getModuleJob (internal/modules/esm/loader.js:113:40)
at ModuleWrap.promises.module.link (internal/modules/esm/module_job.js:32:40)
at link (internal/modules/esm/module_job.js:31:36) code: 'MODULE_NOT_FOUND' }
您知道如何调用.ts文件吗?