简体   繁体   English

错误 TS2307:找不到模块“fs”或其相应的类型声明

[英]error TS2307: Cannot find module 'fs' or its corresponding type declarations

I'm tring to import fs module in my ts component with我正在尝试在我的 ts 组件中导入 fs 模块

import * as fs from 'fs';

I need them for use method writeFile , because I want take data from HTML form and write it in to a JSON file.我需要它们来使用方法writeFile ,因为我想从 HTML 表单中获取数据并将其写入 JSON 文件。 But the console throw me that error:但是控制台向我抛出了这个错误:

error TS2307: Cannot find module 'fs' or its corresponding type declarations.

new-card.component.ts new-card.component.ts

import { Component, OnInit } from '@angular/core';
import jCardList from '../mock-cards.json';
import { Card } from '../ICard';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import * as fs from 'fs';


@Component({
  selector: 'app-new-card',
  templateUrl: './new-card.component.html',
  styleUrls: ['./new-card.component.css']
})

export class NewCardComponent implements OnInit {
  fg: FormGroup;

  constructor(private fb:FormBuilder) { 

    this.fg = this.fb.group({
    id: [{value: 1, disabled: true},[Validators.required]], 
    nome: [{value: null, disabled: false},[Validators.required]],
    manaCost:[{value: null, disabled: false},[Validators.required]],
    colorIdentity:[{value: null, disabled: false},[Validators.required]], 
    type:[{value: null, disabled: false},[Validators.required]],
    subType:[{value: null, disabled: false}],
    effect:[{value: null, disabled: false}],
    att:[{value: null, disabled: false}],
    def:[{value: null, disabled: false}],
    price:[{value: null, disabled: false}],
    });

  }

new-card.component.html new-card.component.html

<div>
  <form [formGroup]="fg" (ngSubmit)="onClick(fg)" > 
    <table>
      <tr>
        <td>Id !:</td>
        <td><input type="number" id="Id" formControlName="id"></td>
      </tr>
      <tr>
        <td>Nome !:</td>
        <td><input formControlName="nome"></td>
      </tr>
      <tr>
        <td>Costo in mana !:</td>
        <td><input type="number" id="manaCost" formControlName="manaCost"></td>
      </tr>
      <tr>
        <td>Colore !:</td>
        <td><input id="colorIdentity" formControlName="colorIdentity"></td>
      </tr>
      <tr>
        <td>Tipo !:</td>
        <td><input id="tipe" formControlName="type"></td>
      </tr>
      <tr>
        <td>Sottotipo:</td>
        <td><input id="subTipe" formControlName="subType"></td>
      </tr>
      <tr>
        <td>Effetto:</td>
        <td><input id="effect" formControlName="effect"></td>
      </tr>
      <tr>
        <td>Forza:</td>
        <td><input type="number" id="att" formControlName="att"></td>
      </tr>
      <tr>
        <td>Costituzione:</td>
        <td><input type="number" id="def" formControlName="def"></td>
      </tr>
      <tr>
        <td>Prezzo:</td>
        <td><input type="number" id="price" formControlName="price"></td>
      </tr>
    </table> 
    <button type="submit" [disabled]="fg.invalid" >Conferma</button>
  </form>
 
</div>

I have already tried to use npm install @types/node --save-dev and add in to the file tsconfig.json inside compilerOptions "types": ["node"],"typeRoots": ["node_modules/@types"], So, if someone can give me an help to troubleshooting this error or give me a different solution I will be glad.我已经尝试使用npm install @types/node --save-dev并添加到文件tsconfig.json里面 compilerOptions "types": ["node"],"typeRoots": ["node_modules/@types"],因此,如果有人可以帮助我解决此错误或给我不同的解决方案,我将很高兴。

在此处输入图像描述

fs it's a built-in package in Node.js, which is server side. fs它是服务器端Node.js中的内置package。 Your code is client-side, you can't use it.您的代码是客户端的,您不能使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到模块“react-lazily”或其相应的类型声明 - Cannot find module 'react-lazily' or its corresponding type declarations node_modules / ngx-bootstrap / chronos / utils / type-checks.d.ts(8,62)中的错误:错误TS2304:找不到名称“提取” - ERROR in node_modules/ngx-bootstrap/chronos/utils/type-checks.d.ts(8,62): error TS2304: Cannot find name 'Extract' 错误TS2304:在angular 5组件中找不到$ - error TS2304: cannot find $ in angular 5 component Electron 版本 12 错误:未捕获错误:找不到模块 - Electron version 12 error: Uncaught Error: Cannot find module Express 4 404错误处理找不到模块&#39;html&#39;错误 - Express 4 404 error handling cannot find module 'html' error TS2304:找不到名称“FormGroup” - TS2304: Cannot find name 'FormGroup' Javascript:为 HTML 属性查找相应的元素和类型 - Javascript: Find corresponding Element and Type for HTML Attribute 在webpack中导入html文件时找不到模块错误 - Cannot find module error on importing html file in webpack Atom 给我错误找不到模块“editorconfig” - Atom is giving me the error Cannot find module 'editorconfig' 错误出现说无法找到模块&#39;../util/http_util&#39; - error appears saying cannot find the module '../util/http_util'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM