TS节点仅在通过NPM运行脚本间接运行时起作用

发布于 2025-02-11 16:28:13 字数 3528 浏览 0 评论 0原文

如果我尝试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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文