我正在尝试使用 ESM 运行我的脚本:
ts-node --esm -r tsconfig-paths/register -T src/server/api/jobs/index.ts
但是,它似乎无法像
import '@/server/init.ts
那样处理我的导入:
CustomError: Cannot find package '@/server' imported from /Users/me/Sites/myapp/src/server/api/jobs/index.ts
我尝试将其添加到我的
tsconfig.json
:
"paths": {
"@/*": ["src/*"]
},
我还尝试更改我的“package.json”的“名称”:
"name": "@/server",
我的文件夹结构是:
/myapp
package.json
tsconfig.json
/src
/server
/api
/jobs
index.ts
这是我的
tsconfig.json
:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"allowImportingTsExtensions": true,
"allowJs": true,
"baseUrl": "./src",
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"incremental": true,
"isolatedModules": true,
"jsx": "preserve",
"lib": ["dom", "dom.iterable", "ES5"],
"module": "ESNext",
"moduleResolution": "NodeNext",
"noEmit": true,
"noUncheckedIndexedAccess": true,
"pretty": true,
"resolveJsonModule": true,
"rootDir": ".",
"skipLibCheck": true,
"strict": true,
"target": "ESNext",
"types": ["node"],
"paths": {
"@/*": ["src/*"]
},
"plugins": [
{
"name": "next"
}
]
},
"include": [
".eslintrc.cjs",
"next-env.d.ts",
"**/*.ts",
"*.js",
"**/*.js",
"**/*.tsx",
"**/*.cjs",
"**/*.mjs",
".next/types/**/*.ts",
"./src/*",
"src/*"
],
"exclude": ["node_modules"]
// "ts-node": {
// "esm": true,
// "experimentalSpecifierResolution": "node",
// "require": ["tsconfig-paths/register"]
// }
}