找不到Angular 5单元测试依赖项

时间:2018-11-22 14:21:25

标签: unit-testing angular-cli

当前,我正在尝试在Angular 5项目上运行单元测试,并且它不断为下面提到的各种文件引发错误“找不到模块”,我试图删除node_modules,然后再次完成install但是错误仍然相同。我在尝试同时运行两个选项(即ng e2eng test)时遇到了这个问题。

ERROR in ./node_modules/saucelabs/index.js                                                                          
Module not found: Error: Can't resolve './lib-cov/SauceLabs' in 'C:\development\web-project\frontend\web\src\main\angular\node_modules\saucelabs'                                                                
ERROR in ./node_modules/protractor/built/bpRunner.js                                                                
Module not found: Error: Can't resolve 'child_process' in 'C:\development\web-project\frontend\web
d-web\src\main\angular\node_modules\protractor\built'                                                               
ERROR in ./node_modules/protractor/built/runner.js                                                                  
Module not found: Error: Can't resolve 'child_process' in 'C:\development\web-project\frontend\web
d-web\src\main\angular\node_modules\protractor\built'                                                               
ERROR in ./node_modules/protractor/built/debugger.js                                                                
Module not found: Error: Can't resolve 'child_process' in 'C:\development\web-project\frontend\web
d-web\src\main\angular\node_modules\protractor\built'                                                               
ERROR in ./node_modules/selenium-webdriver/firefox/binary.js                                                        
Module not found: Error: Can't resolve 'child_process' in 'C:\development\web-project\frontend\web
d-web\src\main\angular\node_modules\selenium-webdriver\firefox'                                                     
ERROR in ./node_modules/selenium-webdriver/io/exec.js                                                               
Module not found: Error: Can't resolve 'child_process' in 'C:\development\web-project\frontend\web
d-web\src\main\angular\node_modules\selenium-webdriver\io'                                                          
ERROR in ./node_modules/selenium-webdriver/net/portprober.js                                                        
Module not found: Error: Can't resolve 'child_process' in 'C:\development\web-project\frontend\web
d-web\src\main\angular\node_modules\selenium-webdriver\net'                                                         
ERROR in ./node_modules/webdriver-js-extender/node_modules/selenium-webdriver/firefox/binary.js                     
Module not found: Error: Can't resolve 'child_process' in 'C:\development\web-project\frontend\web
d-web\src\main\angular\node_modules\webdriver-js-extender\node_modules\selenium-webdriver\firefox'                  
ERROR in ./node_modules/webdriver-js-extender/node_modules/selenium-webdriver/io/exec.js                            
Module not found: Error: Can't resolve 'child_process' in 'C:\development\web-project\frontend\web
d-web\src\main\angular\node_modules\webdriver-js-extender\node_modules\selenium-webdriver\io'                       
ERROR in ./node_modules/webdriver-js-extender/node_modules/selenium-webdriver/net/portprober.js                     
Module not found: Error: Can't resolve 'child_process' in 'C:\development\web-project\frontend\web
d-web\src\main\angular\node_modules\webdriver-js-extender\node_modules\selenium-webdriver\net'                      
ERROR in ./node_modules/protractor/built/debugger.js                                                                
Module not found: Error: Can't resolve 'repl' in 'C:\development\web-project\frontend\web\src
\main\angular\node_modules\protractor\built'                                                                        
ERROR in ./node_modules/blocking-proxy/built/lib/bin.js                                                             
Module parse failed: Unexpected character '#' (1:0)                                                                 
You may need an appropriate loader to handle this file type.                                                        
| #!/usr/bin/env node                                                                                               
| "use strict";                                                                                                     
| Object.defineProperty(exports, "__esModule", { value: true });

我已经验证了saucelabs下的node_modules文件夹,看来还可以。

这是我在Windows 7计算机上安装的软件包:

Angular CLI: 1.7.4                                         
Node: 6.9.1                                                
OS: win32 x64                                              
Angular: 5.2.11                                            
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser               
... platform-browser-dynamic, router, service-worker       

@angular/cdk: 5.2.5                                        
@angular/cli: 1.7.4                                        
@angular-devkit/build-optimizer: 0.3.2                     
@angular-devkit/core: 0.3.2                                
@angular-devkit/schematics: 0.3.2                          
@ngtools/json-schema: 1.2.0                                
@ngtools/webpack: 1.10.2                                   
@schematics/angular: 0.3.2                                 
@schematics/package-update: 0.3.2                          
typescript: 2.4.2                                          
webpack: 3.11.0

我尝试了很多搜索,但是没有找到任何直接的解决方案。例如,发布在github https://github.com/travis-ci/travis-ci/issues/7858上的这个问题与我有点相似,但这并没有为这个问题提供任何具体的解决方案。

如果有人可以帮助我理解该问题以及如何解决该问题,那么我将非常感谢您。

谢谢!

0 个答案:

没有答案