Angular 7 如何使用 fs 模块? [英] Angular 7 how to use fs module?
问题描述
我使用的是 Angular 7.
I'm using Angular 7.
我尝试在 Typescript 上使用 fs 模块打开一个目录.我总是有这个错误:找不到模块:错误:无法解析 fs"类型@node 和文件系统已安装.
I tried to use fs module on Typescript for open a directory. I always have this error: "Module not found: Error: Can't resolve fs" types@node and file-system are installed.
我的代码:
import {Component, OnInit} from '@angular/core';
import * as fs from 'file-system';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
title = 'my-app';
constructor() {
}
ngOnInit() {
console.log(fs);
}
}
你能帮我吗?
节点:v10.14.0NPM:v6.4.1Angular CLI:v7.1.1
Node : v10.14.0 Npm: v6.4.1 Angular CLI: v7.1.1
推荐答案
'fs' 是 NodeJS 运行时的库,但 Angular 管道捆绑器的最终产品是在浏览器中运行的前端 SPA 客户端.如果您需要从用户的本地文件系统将文件加载到客户端,那么您需要使用浏览器本机变体,例如看看处理 元素.
'fs' is a library for NodeJS runtime, but the end product of the Angular pipeline bundler is a frontend SPA client which runs in a browser. If you need to load a file into the client from the user's local filesystem then you need to use browser native variant e.g. take a look at handling <input type="file">
elements.
这篇关于Angular 7 如何使用 fs 模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!