TS节点仅在通过NPM运行脚本间接运行时起作用
如果我尝试ts-node src/main.ts
,我会得到
$ ts-node src/main.ts ↵ 1 04:15:21
/home/mm/proj/university-bot/node_modules/typescript/lib/typescript.js:42537
ts.Debug.assert(typeof typeReferenceDirectiveName === "string", "Non-string value passed to `ts.resolveTypeReferenceDirective`, likely by a wrapping package working with an outdated `resolveTypeReferenceDirectives` signature. This is probably not a problem in TS itself.");
^
Error: Debug Failure. False expression: Non-string value passed to `ts.resolveTypeReferenceDirective`, likely by a wrapping package working with an outdated `resolveTypeReferenceDirectives` signature. This is probably not a problem in TS itself.
at Object.resolveTypeReferenceDirective (/home/mm/proj/university-bot/node_modules/typescript/lib/typescript.js:42537:18)
at /usr/lib/node_modules/ts-node/src/resolver-functions.ts:131:51
at Array.map (<anonymous>)
at Object.resolveTypeReferenceDirectives (/usr/lib/node_modules/ts-node/src/resolver-functions.ts:130:31)
at actualResolveTypeReferenceDirectiveNamesWorker (/home/mm/proj/university-bot/node_modules/typescript/lib/typescript.js:116674:163)
at resolveTypeReferenceDirectiveNamesWorker (/home/mm/proj/university-bot/node_modules/typescript/lib/typescript.js:116974:26)
at processTypeReferenceDirectives (/home/mm/proj/university-bot/node_modules/typescript/lib/typescript.js:118456:31)
at findSourceFileWorker (/home/mm/proj/university-bot/node_modules/typescript/lib/typescript.js:118341:21)
at findSourceFile (/home/mm/proj/university-bot/node_modules/typescript/lib/typescript.js:118196:26)
at processImportedModules (/home/mm/proj/university-bot/node_modules/typescript/lib/typescript.js:118602:25)
,但是当我运行npm运行启动
时,它可以解决ts-node src/main.ts
,它可以工作
$ npm run start ↵ 1 04:17:59
> [email protected] start
> ts-node src/main.ts
Ready!
我的tsconfig.json
:
{
"compilerOptions": {
/* Language and Environment */
"target": "es2016",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
/* Type Checking */
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
/* Completeness */
"skipLibCheck": true
}
}
我的package.json
:
{
"name": "university-bot",
"version": "1.0.0",
"description": "",
"main": "main.ts",
"scripts": {
"start": "ts-node src/main.ts",
"deploy": "ts-node src/deploy-commands.ts"
},
"keywords": [],
"author": "Michael Moreno",
"license": "ISC",
"dependencies": {
"@discordjs/builders": "^0.15.0",
"@discordjs/rest": "^0.5.0",
"discord-api-types": "^0.35.0",
"discord.js": "^13.8.1",
"dotenv": "^16.0.1"
},
"devDependencies": {
"@types/node": "^18.0.0",
"ts-node": "^10.8.1",
"typescript": "^4.7.4"
}
}
If I try ts-node src/main.ts
, I get
$ ts-node src/main.ts ↵ 1 04:15:21
/home/mm/proj/university-bot/node_modules/typescript/lib/typescript.js:42537
ts.Debug.assert(typeof typeReferenceDirectiveName === "string", "Non-string value passed to `ts.resolveTypeReferenceDirective`, likely by a wrapping package working with an outdated `resolveTypeReferenceDirectives` signature. This is probably not a problem in TS itself.");
^
Error: Debug Failure. False expression: Non-string value passed to `ts.resolveTypeReferenceDirective`, likely by a wrapping package working with an outdated `resolveTypeReferenceDirectives` signature. This is probably not a problem in TS itself.
at Object.resolveTypeReferenceDirective (/home/mm/proj/university-bot/node_modules/typescript/lib/typescript.js:42537:18)
at /usr/lib/node_modules/ts-node/src/resolver-functions.ts:131:51
at Array.map (<anonymous>)
at Object.resolveTypeReferenceDirectives (/usr/lib/node_modules/ts-node/src/resolver-functions.ts:130:31)
at actualResolveTypeReferenceDirectiveNamesWorker (/home/mm/proj/university-bot/node_modules/typescript/lib/typescript.js:116674:163)
at resolveTypeReferenceDirectiveNamesWorker (/home/mm/proj/university-bot/node_modules/typescript/lib/typescript.js:116974:26)
at processTypeReferenceDirectives (/home/mm/proj/university-bot/node_modules/typescript/lib/typescript.js:118456:31)
at findSourceFileWorker (/home/mm/proj/university-bot/node_modules/typescript/lib/typescript.js:118341:21)
at findSourceFile (/home/mm/proj/university-bot/node_modules/typescript/lib/typescript.js:118196:26)
at processImportedModules (/home/mm/proj/university-bot/node_modules/typescript/lib/typescript.js:118602:25)
but when I run npm run start
, which resolves to ts-node src/main.ts
, it works
$ npm run start ↵ 1 04:17:59
> [email protected] start
> ts-node src/main.ts
Ready!
my tsconfig.json
:
{
"compilerOptions": {
/* Language and Environment */
"target": "es2016",
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
/* Type Checking */
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
/* Completeness */
"skipLibCheck": true
}
}
my package.json
:
{
"name": "university-bot",
"version": "1.0.0",
"description": "",
"main": "main.ts",
"scripts": {
"start": "ts-node src/main.ts",
"deploy": "ts-node src/deploy-commands.ts"
},
"keywords": [],
"author": "Michael Moreno",
"license": "ISC",
"dependencies": {
"@discordjs/builders": "^0.15.0",
"@discordjs/rest": "^0.5.0",
"discord-api-types": "^0.35.0",
"discord.js": "^13.8.1",
"dotenv": "^16.0.1"
},
"devDependencies": {
"@types/node": "^18.0.0",
"ts-node": "^10.8.1",
"typescript": "^4.7.4"
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论