node.js - 在 Angular 应用程序中,我不断收到此错误 Cannot find module 'fs'

标签 node.js angular

在我的服务文件中,我导入这四个库:

import * as async from "async";
import * as officegen from "officegen";
import * as path from "path";
import * as fs from "fs";

虽然async、officegen和path没有问题。 fs 行不断给出此错误:

ERROR in src/app/matieres/matiere.service.ts(11,45): error TS2307: Cannot find module 'fs'.

在绝望的尝试中,我尝试了这些:

npm install fs -g

npm install fs --save

npm install file-system -g

npm install file-system --save

没有一个有效 这实在令人困惑。 有人可以帮忙吗?

最佳答案

您可能需要使用npm install --save-dev @types/node

可能还需要检查 tsconfig.json 中的 "moduleResolution": "node"

如果这没有帮助,这些其他问题看起来类似:

Cannot find module 'fs'

Use fs in typescript

关于node.js - 在 Angular 应用程序中,我不断收到此错误 Cannot find module 'fs',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56546970/

相关文章:

node.js - 回溯在 peg.js 中是如何工作的(有例子)?

node.js - Electron 锻造,制作命令: override default values

javascript - 在没有angularfire的情况下以 Angular 6初始化firebase

json - 使用 Ag-grid 将 JSON 导出到 excel (csv)

javascript - 将 UTC 时间转换为本地时间( Angular )

html - Angular 5 : Spinner is not working perfectly on page load

javascript - 无法从 Azure Web App 连接到 Azure Redis 缓存

javascript - rails Assets 管道 javascript "SyntaxError: Unexpected token export"

javascript - 将 Node gm 与 Promise 和 buffer 一起使用

angular - 在升级到 Angular 9 期间,Typescript 编译中缺少 main.ts 和 polyfills.ts