首页 > 解决方案 > ts-node 错误:找不到模块“进程”或其相应的类型声明

问题描述

ts-node 给了我这个错误:

找不到模块“进程”或其相应的类型声明。

这是我的 tsconfig.json

{
  "compilerOptions": {
    "types": [ "node "],
    "declaration": true,
    "target": "ESNext",
    "module": "CommonJS",
    "outDir": "./dist",
    "rootDir": "./src",
    "moduleResolution": "node"
  }
}

这是我的 package.json

{
  "name": "example",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "author": "Seph Reed",
  "license": "ISC",
  "devDependencies": {
    "@types/node": "^14.14.9",
    "ts-node": "^9.0.0",
    "typescript": "^4.1.2"
  }
}

为什么我会收到此错误?

标签: typescriptts-node

解决方案


如此愚蠢。上面有空位"types": [ "node "],

此外,如果您像这样导入,您只会收到我列出的错误:

import { argv } from 'process';

如果你只使用没有 import 语句的变量,你会得到错误:

找不到名称“进程”。您需要为节点安装类型定义吗?尝试npm i --save-dev @types/node然后添加node到 tsconfig.xml 中的类型字段。

为了便于搜索,我将不删除这个问题。我真的找不到在其他任何地方列出的这个错误。


推荐阅读