使用TS-Node-dev运行一个简单的Express应用并获得错误:false表达式:非弦乐值传递给`ts.resolvetyperecredendedircordertive“

发布于 2025-02-01 05:48:33 字数 2587 浏览 5 评论 0原文

我是Typescript的新手,并表示。我正在尝试使用ts-node-dev运行最简单的快递应用程序,但要获取以下错误。

> ./node_modules/.bin/ts-node-dev src/index.ts                                                 16:07:40
[INFO] 16:07:42 ts-node-dev ver. 1.1.8 (using ts-node ver. 9.1.1, typescript ver. 4.7.2)
Compilation error in /home/lht/microservice/ticketing/auth/src/index.ts
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.<anonymous> (/home/lht/microservice/ticketing/auth/src/index.ts:1:7)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Module._compile (/home/lht/microservice/ticketing/auth/node_modules/source-map-support/source-map-support.js:568:25)
    at Module.m._compile (/tmp/ts-node-dev-hook-8101223397369532.js:69:33)
    at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at require.extensions.(anonymous function) (/tmp/ts-node-dev-hook-8101223397369532.js:71:20)
    at Object.nodeDevHook [as .ts] (/home/lht/microservice/ticketing/auth/node_modules/ts-node-dev/lib/hook.js:63:13)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
[ERROR] 16:07:42 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.

以下是我的index.ts文件。

import express from "express";
import { json } from "body-parser";

const app = express();
app.use(json());

app.listen(3000, () => {
  console.log("Listening on port 3000!");
});

这是我的package.json文件,

{
  "name": "auth",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "ts-node src/index.ts"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {},
  "dependencies": {
    "@types/express": "^4.17.13",
    "@types/node": "^17.0.35",
    "express": "^4.18.1",
    "ts-node": "^10.8.0",
    "ts-node-dev": "^1.1.8",
    "typescript": "^4.7.2"
  }
}

我想知道我正在做的某些配置是否错误。提前致谢。

I am new to typescript and express. I am trying to run the simplest express app using ts-node-dev, but get the following error.

> ./node_modules/.bin/ts-node-dev src/index.ts                                                 16:07:40
[INFO] 16:07:42 ts-node-dev ver. 1.1.8 (using ts-node ver. 9.1.1, typescript ver. 4.7.2)
Compilation error in /home/lht/microservice/ticketing/auth/src/index.ts
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.<anonymous> (/home/lht/microservice/ticketing/auth/src/index.ts:1:7)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Module._compile (/home/lht/microservice/ticketing/auth/node_modules/source-map-support/source-map-support.js:568:25)
    at Module.m._compile (/tmp/ts-node-dev-hook-8101223397369532.js:69:33)
    at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at require.extensions.(anonymous function) (/tmp/ts-node-dev-hook-8101223397369532.js:71:20)
    at Object.nodeDevHook [as .ts] (/home/lht/microservice/ticketing/auth/node_modules/ts-node-dev/lib/hook.js:63:13)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
[ERROR] 16:07:42 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.

The following is my index.ts file.

import express from "express";
import { json } from "body-parser";

const app = express();
app.use(json());

app.listen(3000, () => {
  console.log("Listening on port 3000!");
});

This is my package.json file

{
  "name": "auth",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "ts-node src/index.ts"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {},
  "dependencies": {
    "@types/express": "^4.17.13",
    "@types/node": "^17.0.35",
    "express": "^4.18.1",
    "ts-node": "^10.8.0",
    "ts-node-dev": "^1.1.8",
    "typescript": "^4.7.2"
  }
}

I wonder if there are some configurations that I am doing are wrong. Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

情释 2025-02-08 05:48:33

只需将ts-node-dev1.1.8更改为2.0.0-0-0-0-0在我的package.json 文件,然后再次运行npm安装,并且错误消失了。

{
  "name": "auth",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "ts-node src/index.ts"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {},
  "dependencies": {
    "@types/express": "^4.17.13",
    "@types/node": "^17.0.35",
    "express": "^4.18.1",
    "ts-node": "^10.8.0",
    "ts-node-dev": "^2.0.0-0",
    "typescript": "^4.7.2"
  }
}

Just change the ts-node-dev version from 1.1.8 to 2.0.0-0 in my package.json file, then run npm install again, and the error disappears.

{
  "name": "auth",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "ts-node src/index.ts"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {},
  "dependencies": {
    "@types/express": "^4.17.13",
    "@types/node": "^17.0.35",
    "express": "^4.18.1",
    "ts-node": "^10.8.0",
    "ts-node-dev": "^2.0.0-0",
    "typescript": "^4.7.2"
  }
}
场罚期间 2025-02-08 05:48:33

我从新鲜构建的Typeorm应用程序(npx create-express-typescript-application my-app -t typeorm)中遇到了这一点。颠簸ts-node to ^10.8.0解决了问题。

I ran into this from a freshly built typeorm app (npx create-express-typescript-application my-app -t typeorm). Bumping ts-node to ^10.8.0 solved the issue.

南薇 2025-02-08 05:48:33

我观察到,为什么其他服务正常工作,除了一项。
我发现,失败的服务正在使用不同的TS版本进行编译。
在将TS版本更改

"typescript": "^4.6.3"

"typescript": "4.6.4"

之后,也解决了问题。

I observed, why other services are working fine, except one.
I found that, the failing service was getting compiled with different TS version.
After I changed TS version

"typescript": "^4.6.3"

to

"typescript": "4.6.4"

that also solved the issue.
enter image description here

浮生未歇 2025-02-08 05:48:33

一个快速简便的修复程序是运行npm intern typeScript@最新ts-node@最新。问题可能是旧的TS节点与最新的打字稿4.7.x版本不兼容,并升级它们解决了我的问题。

A quick and easy fix is to run npm install typescript@latest ts-node@latest. The problem may be the old ts-node is incompatible with the latest typescript 4.7.x release and upgrade them fix my issue.

甜是你 2025-02-08 05:48:33

当尝试使用Nodemon在纱线工作区内运行节点服务器时,我只是遇到了这个问题。从工作区子文件夹中运行nodemon,但无法从工作区根文件夹本身。

worspace子文件夹中的脚本看起来像这样

"dev": "nodemon"

,从根文件夹中,

"dev:my-service": "yarn workspace my-service dev"

我通过专门将ts节点作为dev依赖关系求解了“ my-service”工作区

I just ran into this problem when trying to run a node server inside a yarn workspace with nodemon. Running nodemon from the workspace sub folder worked, but not from workspace root folder itself.

Script in worspace sub folder looks like this

"dev": "nodemon"

and from root folder

"dev:my-service": "yarn workspace my-service dev"

I solved it by specifically adding ts-node as a dev dependency to the "my-service" workspace

So尛奶瓶 2025-02-08 05:48:33

只需将ts节点的版本更改

    "ts-node": "10.8.1",

运行npm iyarn

just change the version of ts-node

to

    "ts-node": "10.8.1",

run npm i or yarn

初雪 2025-02-08 05:48:33

运行:

npm uninstall ts-node && npm uninstall ts-node-dev

然后运行:

npm i ts-node && npm i ts-node-dev --save-dev

Run:

npm uninstall ts-node && npm uninstall ts-node-dev

and then run:

npm i ts-node && npm i ts-node-dev --save-dev
木格 2025-02-08 05:48:33

而不是使用:
ts-node-dev - respawn -transpile-inly server.ts

我使用了:
ts-node-dev -Respawn server.ts
而且有效。

Instead of using:
ts-node-dev --respawn --transpile-only server.ts

I used:
ts-node-dev --respawn server.ts
and it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文