当我尝试使用
writeFile
时,Angular会从fs中导入它,然后我尝试运行ng serve
,但我收到了错误消息ERROR in src/app/app.component.ts(2,27): error TS2307: Cannot find module 'fs'.
我猜测我可能错过了某些简单的选项,就像你想使用ng-model
一样,你需要在app.modules.ts
中导入formsModule
。
我正在使用:
vscode: 1.34
Angular CLI: 8.0.1
Node: 10.15.3
OS: win32 x64
Angular: 8.0.0
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.800.1
@angular-devkit/build-angular 0.800.1
@angular-devkit/build-optimizer 0.800.1
@angular-devkit/build-webpack 0.800.1
@angular-devkit/core 8.0.1
@angular-devkit/schematics 8.0.1
@angular/cli 8.0.1
@ngtools/webpack 8.0.1
@schematics/angular 8.0.1
@schematics/update 0.800.1
rxjs 6.4.0
typescript 3.4.5
webpack 4.30.0
我的tsconfig
文件如下:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "esnext",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es2015",
"typeRoots": ["node_modules/@types"],
"lib": ["es2018", "dom"],
"types": ["node"]
}
}
fs
是一个 NodeJS 库。它需要访问操作系统,这是浏览器 JavaScript 所不具备的。你不能在 Angular 中使用它。 - user4676340