测试主项目文件夹之外的角度组件:找不到模块raw-loader

问题描述

所以我想运行ng test并将测试包含在项目文件夹旁边的文件夹中。

mainproject/
|-- src/
|   |-- app/
|   |   |-- home/
|   |   |   |-- home.component.spec.ts  
|   |   |-- app-main.component.spec.ts
|   |-- test.ts
|   |-- tsconfig.spec.json
|-- node_modules/
|-- angular.json
|-- package.json
|-- tsconfig.json
components/
|-- common/
    |-- control-bar/
        |-- control-bar.component.ts
        |-- control-bar.component.spec.ts 

当我在组件文件夹中不包含其他测试的情况下运行ng测试时,它可以按预期工作,但是当我尝试包含其他组件时,ng测试失败并显示以下错误。

ERROR in ../components/common/control-bar/control-bar.component.ts
Module not found: Error: Can't resolve 'raw-loader' in 'absolutepath\repos\components\common\control-bar'
resolve 'raw-loader' in 'absolutepath\repos\components\common\control-bar'
  Parsed request is a module
  No description file found
  resolve as module
    absolutepath\repos\components\common\control-bar\node_modules doesn't exist or is not a directory
    absolutepath\repos\components\common\node_modules doesn't exist or is not a directory
    absolutepath\repos\components\node_modules doesn't exist or is not a directory
    absolutepath\repos\node_modules doesn't exist or is not a directory
    absolutepath\node_modules doesn't exist or is not a directory
    C:\Users\user\Desktop\node_modules doesn't exist or is not a directory
    C:\Users\user\node_modules doesn't exist or is not a directory
    C:\Users\node_modules doesn't exist or is not a directory
    C:\node_modules doesn't exist or is not a directory
    looking for modules in absolutepath\repos\mainproject\node_modules\@angular-devkit\build-angular\node_modules
      using description file: absolutepath\repos\mainproject\node_modules\@angular-devkit\build-angular\package.json (relative path: ./node_modules)
        using description file: C:\Users\user\Desktop\folder absolutepath\repos\mainproject\node_modules\@angular-devkit\build-angular\package.json (relative path: ./node_modules/raw-loader)
          no extension
            absolutepath\repos\mainproject\node_modules\@angular-devkit\build-angular\node_modules\raw-loader doesn't exist
          .js
            absolutepath\repos\mainproject\node_modules\@angular-devkit\build-angular\node_modules\raw-loader.js doesn't exist
          .json
            absolutepath\repos\mainproject\node_modules\@angular-devkit\build-angular\node_modules\raw-loader.json doesn't exist
          as directory
            absolutepath\repos\mainproject\node_modules\@angular-devkit\build-angular\node_modules\raw-loader doesn't exist
[C:\Users\user\Desktop\folder\repos\components\common\control-bar\package.json]
[C:\Users\user\Desktop\folder\repos\components\common\control-bar\node_modules]
[C:\Users\user\Desktop\folder\repos\components\common\node_modules]
[C:\Users\user\Desktop\folder\repos\components\node_modules]
[C:\Users\user\Desktop\folder\repos\node_modules]
[C:\Users\user\Desktop\folder\node_modules]
[C:\Users\user\Desktop\node_modules]
[C:\Users\user\node_modules]
[C:\Users\node_modules]
[C:\node_modules]
[C:\Users\user\Desktop\folder\repos\mainproject\node_modules\@angular-devkit\build-angular\node_modules\raw-loader]
[C:\Users\user\Desktop\folder\repos\mainproject\node_modules\@angular-devkit\build-angular\node_modules\raw-loader.js]
[C:\Users\user\Desktop\folder\repos\mainproject\node_modules\@angular-devkit\build-angular\node_modules\raw-loader.json]
 @ ../components/common/control-bar/control-bar.component.ts 13:34-85
 @ ../components/common/control-bar/control-bar.component.spec.ts
 @ ./src/test.ts

因此原始加载程序似乎丢失或找不到它。要清楚的是,此设置中只有1个node_modules,它位于mainproject文件夹中。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)