After upgrading my Angular project to 8, I get this error when running ng-test --source-map false.
Note: I could not find an import of fs anywhere in my project code. AFAIK, my project has no special need to access the filesystem.
ERROR in ./node_modules/resolve/lib/async.js
Module not found: Error: Can't resolve 'fs' in 'C:\src\myproject\node_modules\resolve\lib'
resolve 'fs' in 'C:\src\myproject\node_modules\resolve\lib'
Parsed request is a module
using description file: C:\src\myproject\node_modules\resolve\package.json (relative path: ./lib)
Field 'browser' doesn't contain a valid alias configuration
resolve as module
looking for modules in C:/src/myproject/src/
using description file: C:\src\myproject\package.json (relative path: ./src/)
Field 'browser' doesn't contain a valid alias configuration
using description file: C:\src\myproject\package.json (relative path: ./src/fs)
no extension
Field 'browser' doesn't contain a valid alias configuration
C:\src\myproject\src\fs doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
C:\src\myproject\src\fs.ts doesn't exist
It looks like there is a library called resolve which requires fs. Here is what I found about resolve:
yarn why resolve
yarn why v1.16.0
[1/4] Why do we have the module "resolve"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "[email protected]"
info Has been hoisted to "resolve"
info Reasons this module exists
- Hoisted from "tslint#resolve"
- Hoisted from "grunt-cli#liftoff#resolve"
- Hoisted from "@angular-devkit#build-angular#postcss-import#resolve"
- Hoisted from "@angular-devkit#build-angular#@babel#core#resolve"
- Hoisted from "grunt-cli#liftoff#rechoir#resolve"
- Hoisted from "@angular#cli#pacote#normalize-package-data#resolve"
=> Found "grunt#[email protected]"
info Reasons this module exists
- "grunt#grunt-cli" depends on it
- Hoisted from "grunt#grunt-cli#resolve"
Done in 0.71s.
It seems normal that command-line tools like the angular CLI build and tslint should access the filesystem... so why is my project failing?
All of the above libs mentioned in yarn why (tslint, grunt-cli, angular-devkit, angular/cli) are listed under devDependencies, which seems OK to me.
Update
After working through a few other issues, I'm getting this error now on both ng serve and ng test. Here are my tsconfig files:
tsconfig.json:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types",
"src/@types"
],
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
tsconfig.spec.json:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/spec",
"types": [
"jasmine",
"node"
]
},
"files": [
"src/test.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
tsconfig.app.json:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": [
"node"
]
},
"files": [
"src/main.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.ts"
],
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}
nodetypes to your tsconfig. It should be something ``` { "extends": "./tsconfig.json", "compilerOptions": { "outDir": "./out-tsc/spec", "types": [ "jasmine", "node" ] } } ``` - Gosha_Fightenng buildI still get the same error. Onng testI now get a different error: stackoverflow.com/questions/58120512/… - RMorriseyfsis used during compilation by build tools, not your app code. - msanford