【问题标题】:ts-node error: Cannot find module 'process' or its corresponding type declarationsts-node 错误:找不到模块“进程”或其相应的类型声明
【发布时间】:2021-03-07 20:25:05
【问题描述】:

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"
  }
}

为什么会出现这个错误?

【问题讨论】:

    标签: typescript ts-node


    【解决方案1】:

    真傻。上面"types": [ "node "],有一个空格。

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

    import { argv } from 'process';
    

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

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

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

    【讨论】:

      猜你喜欢
      • 2023-01-31
      • 2021-04-08
      • 2022-10-06
      • 2021-04-17
      • 2022-12-16
      • 2021-10-16
      • 1970-01-01
      • 2020-11-04
      • 2020-10-19
      相关资源
      最近更新 更多