Escribí una función como esta:
function clean() { fsExtra.remove(sumoDir) } en un archivo llamado commands.js
Exporto esta función de esta manera:
module.exports = {[...], clean: clean, [...]}Necesito llamar a esta función en un componente de Angular TypeScript que usé para mi interfaz.
En primer lugar, creé un módulo con
ng gm casa
luego importo mi función en home.module.ts de esta manera:
import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import * as commands from './../../../src/commands.js' @NgModule({ declarations: [], imports: [ CommonModule ] }) export class HomeModule { } export {commands} Y lo importé en mi home.component.ts
import { Component, OnInit } from '@angular/core'; import {MatCheckboxChange} from "@angular/material/checkbox"; import {commands} from "./home.module" @Component({ selector: 'app-home', templateUrl: './home.component.html', styleUrls: ['./home.component.css'] }) export class HomeComponent implements OnInit { [...] async clean(){ } [...] } Cuando hago una ng build , el resultado es:
Warning: [...]/home.component.css exceeded maximum budget. Budget 2.00 kB was not met by 1.31 kB with a total of 3.31 kB. Error: node_modules/recursive-copy/index.d.ts:1:23 - error TS2307: Cannot find module 'fs' or its corresponding type declarations. 1 import { Stats } from 'fs'; ~~~~ Error: node_modules/recursive-copy/index.d.ts:2:24 - error TS7016: Could not find a declaration file for module 'stream'. '[...]node_modules/stream/index.js' implicitly has an 'any' type. Try npm i --save-dev @types/stream if it exists or add a new declaration (.d.ts) file containing declare module 'stream'; 2 import { Stream } from 'stream';¿Cómo puedo arreglarlo? o ¿Cómo puedo importar correctamente mi función?
No estoy seguro de lo que está tratando de lograr, pero está tratando de usar la biblioteca recursive-copy en Angular mientras está diseñado para Node.js. Angular se ejecuta en el navegador y no hay una API como fs en el navegador porque no tiene acceso al sistema de archivos de la máquina.