Angular ng测试“;无法解析';财政司司长'&引用;更新到8后

Angular ng测试“;无法解析';财政司司长'&引用;更新到8后,angular,angular-cli,Angular,Angular Cli,将Angular project升级到8后,在运行ng test--source map false时出现此错误 注意:我在项目代码中的任何地方都找不到导入的fs。好吧,我的项目没有访问文件系统的特殊需要 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

将Angular project升级到8后,在运行
ng test--source map false
时出现此错误

注意:我在项目代码中的任何地方都找不到导入的
fs
。好吧,我的项目没有访问文件系统的特殊需要

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
看起来有一个名为
resolve
的库,它需要
fs
。以下是我发现的有关
解析的内容:

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 "resolve@1.12.0"
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#resolve@1.1.7"
info Reasons this module exists
   - "grunt#grunt-cli" depends on it
   - Hoisted from "grunt#grunt-cli#resolve"
Done in 0.71s.
命令行工具(如angular CLI build和tslint)应该访问文件系统,这似乎很正常。。。那么为什么我的项目失败了呢

为什么
(tslint、grunt cli、angular devkit、angular/cli)中提到的所有上述LIB都列在
devDependencies
下,我觉得这没问题

更新

在处理了一些其他问题之后,我现在在
ng-serve
ng-test
上都遇到了这个错误。以下是我的tsconfig文件:

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"
  ]
}

经过漫长的尝试和错误消除过程,我找到了罪魁祸首:

import {hasOwnProperty} from 'tslint/lib/utils';

我意外地将
tslint
实用程序函数导入到我的应用程序源代码中。哎呀

经过漫长的尝试和错误消除过程,我找到了罪魁祸首:

import {hasOwnProperty} from 'tslint/lib/utils';

我意外地将
tslint
实用程序函数导入到我的应用程序源代码中。哎呀

看起来您没有将
节点
类型添加到tsconfig。它应该是``{“extends”:“/tsconfig.json”,“compilerOptions”:{“outDir”:“/out tsc/spec”,“types”:[“jasmine”,“node”]}}```@Gosha_Fighten我从CLI生成了一个新的空白项目,该项目工作正常。我将三个tsconfig文件(.json、.app.json、.spec.json)中的所有内容从新项目复制到旧项目中。在
ng build
上,我仍然得到相同的错误。在
ng test
上,我现在得到了一个不同的错误:用我的tsconfig文件的当前内容更新了OP。仅供参考,编译过程中由生成工具使用,而不是由应用程序代码使用。@msinfo是否还有其他信息可供我提供,以帮助了解发生了什么?看起来您没有将
节点
类型添加到tsconfig中。它应该是``{“extends”:“/tsconfig.json”,“compilerOptions”:{“outDir”:“/out tsc/spec”,“types”:[“jasmine”,“node”]}}```@Gosha_Fighten我从CLI生成了一个新的空白项目,该项目工作正常。我将三个tsconfig文件(.json、.app.json、.spec.json)中的所有内容从新项目复制到旧项目中。在
ng build
上,我仍然得到相同的错误。在
ng test
上,我现在得到了一个不同的错误:用我的tsconfig文件的当前内容更新了OP。仅供参考,编译过程中使用的是生成工具,而不是你的应用程序代码。@msinfo是否还有其他信息可以提供,以帮助了解发生了什么?