使用TS-Node-dev运行一个简单的Express应用并获得错误:false表达式:非弦乐值传递给`ts.resolvetyperecredendedircordertive“
我是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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
只需将
ts-node-dev
从1.1.8
更改为2.0.0-0-0-0-0
在我的package.json 文件,然后再次运行
npm安装
,并且错误消失了。Just change the
ts-node-dev
version from1.1.8
to2.0.0-0
in mypackage.json
file, then runnpm install
again, and the error disappears.我从新鲜构建的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
). Bumpingts-node
to^10.8.0
solved the issue.我观察到,为什么其他服务正常工作,除了一项。
我发现,失败的服务正在使用不同的TS版本进行编译。
在将TS版本更改
为
之后,也解决了问题。

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
to
that also solved the issue.

一个快速简便的修复程序是运行
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.当尝试使用Nodemon在纱线工作区内运行节点服务器时,我只是遇到了这个问题。从工作区子文件夹中运行nodemon,但无法从工作区根文件夹本身。
worspace子文件夹中的脚本看起来像这样
,从根文件夹中,
我通过专门将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
and from root folder
I solved it by specifically adding ts-node as a dev dependency to the "my-service" workspace
只需将
ts节点
的版本更改为
运行
npm i
或yarn
just change the version of
ts-node
to
run
npm i
oryarn
运行:
然后运行:
Run:
and then run:
而不是使用:
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.