[英]Running a simple express app with ts-node-dev and get error: False expression: Non-string value passed to `ts.resolveTypeReferenceDirective`
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.我正在尝试使用
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.
The following is my index.ts
file.以下是我的
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!");
});
This is my package.json
file这是我的
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 wonder if there are some configurations that I am doing are wrong.我想知道我正在做的某些配置是否错误。 Thanks in advance.
提前致谢。
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.只需在我的
package.json
文件中将ts-node-dev
版本从1.1.8
更改为2.0.0-0
,然后再次运行npm install
,错误就消失了。
{
"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"
}
}
I observed, why other services are working fine, except one.我观察到,为什么其他服务工作正常,除了一个。 I found that, the failing service was getting compiled with different TS version.
我发现,失败的服务是用不同的 TS 版本编译的。 After I changed TS version
在我更改了 TS 版本之后
"typescript": "^4.6.3"
to至
"typescript": "4.6.4"
I ran into this from a freshly built typeorm app ( npx create-express-typescript-application my-app -t typeorm
).我从一个新构建的 typeorm 应用程序( npx
npx create-express-typescript-application my-app -t typeorm
)中遇到了这个问题。 Bumping ts-node
to ^10.8.0
solved the issue.将
ts-node
碰撞到^10.8.0
解决了这个问题。
A quick and easy fix is to run npm install typescript@latest ts-node@latest
.一个快速简单的解决方法是运行
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.问题可能是旧的 ts-node 与最新的 typescript 4.7.x 版本不兼容,升级它们可以解决我的问题。
I just ran into this problem when trying to run a node server inside a yarn workspace with nodemon.我在尝试使用 nodemon 在纱线工作区中运行节点服务器时遇到了这个问题。 Running nodemon from the workspace sub folder worked, but not from workspace root folder itself.
从工作区子文件夹运行 nodemon 有效,但不能从工作区根文件夹本身运行。
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我通过专门将 ts-node 作为开发依赖项添加到“my-service”工作区来解决它
just change the version of ts-node
只需更改
ts-node
的版本
to至
"ts-node": "10.8.1",
run npm i
or yarn
运行
npm i
或yarn
run npm uninstall ts-node && npm uninstall ts-node-dev
接着
run npm i ts-node && npm i ts-node-dev --save-dev
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.