Eng*_*Eng 8 fs typescript angular angular7
我正在使用Angular 7。
我试图在Typescript上使用fs模块打开目录。我总是遇到以下错误:“未找到模块:错误:无法解析fs”类型@节点和文件系统已安装。
我的代码:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
你能帮助我吗 ?
节点:v10.14.0 Npm:v6.4.1 Angular CLI:v7.1.1
“fs”是 NodeJS 运行时的库,但 Angular 管道捆绑器的最终产品是在浏览器中运行的前端 SPA 客户端。如果您需要从用户的本地文件系统将文件加载到客户端,那么您需要使用浏览器本机变体,例如查看处理<input type="file">元素。