【发布时间】:2022-01-04 11:02:15
【问题描述】:
我写了一个这样的函数:
function clean() {
fsExtra.remove(sumoDir)
}
在名为commands.js的文件中
我是这样导出这个函数的:
module.exports = {[...], clean: clean, [...]}
我需要在我用于前端的 Angular TypeScript 组件中调用此函数。
首先我创建了一个模块
回家
接下来我以这种方式将我的函数导入home.module.ts:
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}
然后我将它导入我的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(){
}
[...]
}
当我执行ng build 时,输出是:
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';
我该如何解决?或如何正确导入我的函数?
【问题讨论】:
标签: javascript node.js angular typescript