Angular 7如何使用fs模块? [英] Angular 7 how to use fs module?
问题描述
我正在使用Angular 7.
I'm using Angular 7.
我试图在Typescript上使用fs模块打开目录. 我总是遇到此错误:找不到模块:错误:无法解析fs" 已经安装了types @ 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.0 Npm:v6.4.1 Angular CLI:v7.1.1
Node : v10.14.0 Npm: v6.4.1 Angular CLI: v7.1.1
推荐答案
'fs'是NodeJS运行时的库,但是Angular Pipeline Bundle的最终产品是在浏览器中运行的前端SPA客户端.如果您需要从用户的本地文件系统中将文件加载到客户端,则需要使用浏览器的本机变体,例如看一下处理<input type="file">
元素.
'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屋!