gpt4 book ai didi

node.js - 如何在 Node 应用程序中使用@types/node

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

我在 Ubuntu 16.04 上使用 VSCode。我使用以下逗号创建了 Node 项目:

npm init
tsc --init

我创建了一个名为 index.ts 的新文件。我正在尝试使用 fs 和 readling 来读取文件内容。但是当我在 index.d.ts 的顶部编写以下代码行时:

import fs = require('fs');
import readline = require('readline');

我遇到以下错误:找不到模块“fs”找不到模块“readline”

进程都找不到。我已经安装了来自 here 的 Node 类型使用以下命令:

sudo npm install @types/node -global --save

谁能帮我解决这个错误?

最佳答案

从 TypeScript 2.x 开始,所有类型都使用 npm 安装,如下所示:npm install @types/node

关于node.js - 如何在 Node 应用程序中使用@types/node,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39540163/

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