gpt4 book ai didi

typescript 错误 "Cannot find name ' 需要'。并且找不到名称 'process'。”

转载 作者:搜寻专家 更新时间:2023-10-30 21:19:32 32 4
gpt4 key购买 nike

Typescript 错误“找不到名称‘require’。并且找不到名称‘process’。”即使它已经在其编译器选项中定义了参数 "moduleResolution": "node"

下面是我当前的tsconfig.json

{
"compilerOptions": {
"target": "es2015",
"lib": ["es2015", "es6"],
"types": ["reflect-metadata"],
"moduleResolution": "node",
"module": "commonjs",
"rootDir": "src",
"outDir": "./build",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"declaration": false
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules"
]
}

最佳答案

默认情况下不捆绑 Node.js 标准库的类型定义。您需要通过 @types/node 包自行安装它们:

npm install --save @types/node

moduleResolution 选项控制 how the compiler handles import statements ,与 Node.js 标准库无关。

要修复“找不到名称‘require’”错误,您还应该将任何 CommonJS 导入转换为使用 TypeScript 导入语法:

// Before
var process = require('process');

// After
import process = require('process');

参见 Migrating from JavaScript有关详细信息,请参阅 TypeScript 手册部分。

关于 typescript 错误 "Cannot find name ' 需要'。并且找不到名称 'process'。”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48757587/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com