简体   繁体   English

使用 ts-node-dev 运行一个简单的 express 应用程序并得到错误:错误表达式:传递给 `ts.resolveTypeReferenceDirective` 的非字符串值

[英]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"

that also solved the issue.这也解决了这个问题。 在此处输入图像描述

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 iyarn

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.

相关问题 错误表达式:传递给 `ts.resolveTypeReferenceDirective` 的非字符串值 - False expression: Non-string value passed to `ts.resolveTypeReferenceDirective` 错误:调试失败。 错误表达式:传递给 `ts.resolveTypeReferenceDirective` 的非字符串值, - Error: Debug Failure. False expression: Non-string value passed to `ts.resolveTypeReferenceDirective`, 打字稿:调试失败。 错误表达式:传递给 ts.resolveTypeReferenceDirective 的非字符串值 - Typescript: Debug Failure. False expression: Non-string value passed to `ts.resolveTypeReferenceDirective` ts-node-dev 不打印 ts 错误 - ts-node-dev not printing ts errors 运行 ts-node-dev 时,ts-node 的“main”条目无效 - Invalid “main” entry for ts-node when running ts-node-dev Npm i ts-node-dev --save-dev 导致没有这样的文件或目录,chmod node_modules/ts-node-dev/lib\bin.js' - Npm i ts-node-dev --save-dev leads to no such file or directory, chmod node_modules/ts-node-dev/lib\bin.js' 角度-TS-错误TS1109:期望表达 - Angular - TS - Error TS1109: Expression Expected 适应React TS后TS运行树视图时出错 - TS error running treeview after adapting for React TS 正则表达式:匹配 Javascript 中的小数(用于非字符串变量) - Regular Expression: Matching decimals in Javascript (for non-string variables) 字符串在非字符串后未在Node.js中格式化 - Strings not formatted in Node.js after a non-string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM