标签: ts-node-dev

错误表达式:在打字稿中传递给“ts.resolveTypeReferenceDirective”的非字符串值

当我尝试运行 ts-node-dev./index.ts 时,出现以下错误,我更新了我的打字稿和 ts-node-dev、ts-node,但如果我删除具有 @types 的依赖项,此错误会继续弹出/XXXX(例如:@types/express)它工作正常。

错误表达式:传递给 的非字符串值ts.resolveTypeReferenceDirective,可能是由使用过时签名的包装包造成的resolveTypeReferenceDirectives。这可能不是TS本身的问题。

    "dependencies": {
    "ajv": "^8.9.0",
    "axios": "^0.27.1",
    "exceljs": "^4.3.0",
    "express": "^4.17.1",
    "json2csv": "^5.0.7",
    "moment-timezone": "^0.5.33",
    "mysql": "^2.18.1",
    "mysql-utilities": "^1.1.3",
    "q": "^1.5.1",
    "ts-node": "^10.8.0",
    "ts-node-dev": "^2.0.0",
    "typescript": "^4.7.2",
    "winston": "^3.3.3",
    "winston-daily-rotate-file": "^4.5.5"
  },
  "devDependencies": {
    "@types/chai": "^4.2.22",
    "@types/express": "^4.17.11",
    "@types/jest": "^27.4.0",
    "@types/mocha": "^9.0.0",
    "@types/mysql": "^2.15.20",
    "@types/node": "^15.6.1",
    "chai": "^4.3.4",
    "jest": "^27.4.7",
    "mocha": "^9.1.2",
    "ts-jest": "^27.1.3"
  },
Run Code Online (Sandbox Code Playgroud)

typescript ts-node ts-node-dev

121
推荐指数
4
解决办法
10万
查看次数

在从打字稿编译的代码中导入 PrismaClient 时出错 [SyntaxError: 未找到命名导出“PrismaClient”]

在 server.ts 中,像这样导入 PrismaClient:

import { PrismaClient } from '@prisma/client';

export const prisma = new PrismaClient();
Run Code Online (Sandbox Code Playgroud)

使用 tsc 构建并运行编译后的代码时抛出错误:

yarn run build && yarn run start

import { PrismaClient } from '@prisma/client';
         ^^^^^^^^^^^^
SyntaxError: Named export 'PrismaClient' not found. The requested module '@prisma/client' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

    import pkg from '@prisma/client';
    const { PrismaClient } = pkg;
    
        at …
Run Code Online (Sandbox Code Playgroud)

node.js express typescript prisma ts-node-dev

8
推荐指数
2
解决办法
3万
查看次数

ts-node-dev 遇到错误:“找不到模块‘typescript’”

我正在尝试设置一个基本的 Nest.js 应用程序。

main.js 位于 src 文件夹中。我运行这个命令:

  npx ts-node-dev src/main.ts
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Cannot find module 'typescript'
Require stack:
- /home/yilmaz/.npm/_npx/429895/lib/node_modules/ts-node-dev/lib/index.js
- /home/yilmaz/.npm/_npx/429895/lib/node_modules/ts-node-dev/lib/bin.js
Run Code Online (Sandbox Code Playgroud)

我全局安装了 typescript,关闭终端并重新启动它。运行tsc -v,我得到“版本 4.3.5”,但错误尚未解决。

这是 tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es2017",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}
Run Code Online (Sandbox Code Playgroud)

安装打字稿后,我重新创建了该文件并tsc --init 启用了

    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
Run Code Online (Sandbox Code Playgroud)

node.js typescript nestjs npx ts-node-dev

8
推荐指数
1
解决办法
5730
查看次数

未找到命令:ts-node-dev

我正在从 移动nodemonts-node-dev但我无法使用 运行我的index.ts文件ts-node-dev

我做了以下事情:

  1. yarn add ts-node-dev --dev

  2. 在我的package.json我有:

    "devDependencies": {
       ...
       "nodemon": "^1.19.2",
       "ts-node": "8.3.0",
       "ts-node-dev": "^1.0.0-pre.56",
       "typescript": "3.6.3"
    }
    
    Run Code Online (Sandbox Code Playgroud)

如果我运行ts-node-devts-node-dev src/index.ts收到错误: 找不到命令:ts-node-dev

我究竟做错了什么?在我看来,安装正确。

我的脚本

   "scripts": {
      "start": "nodemon --exec ts-node src/index.ts",
      "dev": "ts-node-dev src/index.ts"
   }
Run Code Online (Sandbox Code Playgroud)

node.js typescript ts-node-dev

7
推荐指数
1
解决办法
3万
查看次数

为 VS Code / ts-node / ts-node-dev 指定备用 tsconfig.json

我正在将我的项目从 JavaScript 迁移到 Typescript。

我希望tsconfig.json在 VS Code 中默认显示更严格的警告,但有一个替代方案,tsconfig.json具有更宽松的tsc编译器选项,以允许成功构建。

迁移计划是随着时间的推移逐渐strict确定备用的 just-compile-it-dammit 文件中的选项tsconfig-dev.json

我可以通过--project alt-tsconfig.jsontsc指定替代方案tsconfig.json

如何指定与andtsconfig.json一起使用哪个?ts-nodets-node-dev

tsconfig visual-studio-code ts-node ts-node-dev

6
推荐指数
1
解决办法
2427
查看次数

如何同时使用普通导入和顶级等待?

import x from y我想在 ts-node 中同时使用导入 ( ) 和顶级等待。但是,如果我按照顶级等待的要求将我的更改tsconfig.compilerOptions.module为或更高,我会得到:es2017

SyntaxError: Cannot use import statement outside a module
Run Code Online (Sandbox Code Playgroud)

解决这个问题是根据无数的 GH 问题和 SO 问题来设置,从而导致tsconfig.compilerOptions.modulecommonjs

Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', or 'nodenext', and the 'target' option is set to 'es2017' or higher
Run Code Online (Sandbox Code Playgroud)

我怎样才能两者兼得?一定有办法...

tsconfig.json:

{
  "compilerOptions": {
    "declaration": true,
    "module": "esnext",
    "target": "es2017",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "noImplicitAny": true,
    "removeComments": true,
    "preserveConstEnums": true,
    "sourceMap": true, …
Run Code Online (Sandbox Code Playgroud)

typescript tsconfig ts-node ts-node-dev

6
推荐指数
0
解决办法
1397
查看次数

在使用 ts-node-dev 的导入语句附近收到错误“SyntaxError: Unexpected string”

我尝试将打字稿库与节点一起使用,但我不断收到这些语法错误。我正在使用 ts-node-dev 运行 package.json 中的开发脚本。错误显示在导入语句附近,我不确定我的 tsconfig.json 是否有问题(它也附在下面)。但我正在使用 "module":"commonjs" 。

[INFO] 13:22:15 ts-node-dev ver. 1.1.8 (using ts-node ver. 9.1.1, typescript ver. 4.4.3)
/mnt/d/Polkadex/web-proxy/node_modules/@polkadot/keyring/index.js:3
import "./detectPackage.js";
       ^^^^^^^^^^^^^^^^^^^^ 

SyntaxError: Unexpected string
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Module._compile (/mnt/d/Polkadex/web-proxy/node_modules/source-map-support/source-map-support.js:568:25)
    at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Object.nodeDevHook [as .js] (/mnt/d/Polkadex/web-proxy/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)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/mnt/d/Polkadex/web-proxy/src/helpers/testUser.ts:1:1)
[ERROR] 13:22:19 SyntaxError: Unexpected string
Run Code Online (Sandbox Code Playgroud)

包.json

[INFO] 13:22:15 ts-node-dev ver. 1.1.8 (using ts-node ver. 9.1.1, typescript ver. 4.4.3)
/mnt/d/Polkadex/web-proxy/node_modules/@polkadot/keyring/index.js:3
import …
Run Code Online (Sandbox Code Playgroud)

node.js typescript ts-node polkadot-js ts-node-dev

3
推荐指数
1
解决办法
3443
查看次数

ts-node-dev:使用 dotenv 时没有提供要运行的脚本

我有一个脚本,package.json在使用标准文件时按预期运行.env

"scripts": {
  "commands": "ts-node-dev --files deploy-commands.ts",
},
Run Code Online (Sandbox Code Playgroud)

但是当我尝试指定不同的 .env 文件时 ( .env.prod)

"scripts": {
  "commands": "dotenv -e .env.prod ts-node-dev --files deploy-commands.ts",
},
Run Code Online (Sandbox Code Playgroud)

我收到错误:

ts-node-dev: no script to run provided
Run Code Online (Sandbox Code Playgroud)

typescript ts-node dotenv ts-node-dev

3
推荐指数
1
解决办法
2623
查看次数

无法从 TypeScript 反射系统推断 GraphQL 类型。您需要为“Address”类的“id”提供显式类型

import { ObjectType, ID, Int, Field } from 'type-graphql';
@ObjectType()
export default class Address {
  @Field(type => ID)
  id: String;

  @Field()
  type: string;

  @Field()
  title: string;

  @Field()
  location: string;
}
Run Code Online (Sandbox Code Playgroud)

信息:ts-node-dev 版本。1.0.0(使用 ts-node 版本 9.1.1,typescript 版本 4.0.5)

使用此命令启动应用程序时ts-node-dev --respawn server.shop.ts 出现以下错误。(无法从 TypeScript 反射系统推断 GraphQL 类型。您需要为“Address”类的“id”提供显式类型。)

typescript typegraphql ts-node-dev

1
推荐指数
1
解决办法
4796
查看次数