如何修复 15:exec:node:在 Windows 上使用 Typescript 在 NodeJS 项目中找不到?

问题描述 投票:0回答:1

我是 Nodejs 和 Typescript 的新手,在 Windows 机器上遇到问题。我设置了一个带有单个 index.ts 的空项目,仅供测试之用。我也在使用nodemon。

当我使用

tsc
命令从ts生成js文件时,它运行没有任何错误,并且文件构建在build目录中。

enter image description here

但是当我想使用节点的启动脚本(使用nodemon)来执行此操作时,它会抛出错误。

有什么想法为什么会发生以及如何解决它吗?

enter image description here

Node、ts-node、tsc 已安装:

enter image description here

这是我的package.json:

{
  "name": "signal-service",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "nodemon"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": "",
  "devDependencies": {
    "@tsconfig/node20": "^20.1.4",
    "@types/node": "^22.7.7",
    "nodemon": "^3.1.7",
    "ts-node": "^10.9.2",
    "typescript": "^5.6.3"
  }
}

这是我的 tsconfig.json:

{
  "extends": "@tsconfig/node20/tsconfig.json",
  "compilerOptions": {
    "rootDir": "./src",
    "outDir": "./build",
    "forceConsistentCasingInFileNames": true
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules",
    "build"
  ]
}

这是我的nodemon.json:

{
  "watch": [
    "src"
  ],
  "ext": "js,ts,json",
  "exec": "ts-node ./src/index.ts"
}

我尝试在我的计算机上重新安装节点并从头开始设置项目几次。

javascript node.js typescript windows nodemon
1个回答
0
投票

您是否尝试过使用 cmd.exe 而不是 PowerShell?根据我的经验,在 Windows 上使用 PowerShell 会出现问题。

首先,尝试在 cmd.exe 中运行同一文件夹。如果有效,请将 Webstorm 的终端替换为 cmd 甚至 git bash。这是如何操作的说明:https://www.jetbrains.com/help/webstorm/terminal-emulator.html#open-terminal

© www.soinside.com 2019 - 2024. All rights reserved.