简体   繁体   English

找不到条目模块中的错误:错误:无法解析/src/test.ts

[英]ERROR in Entry module not found: Error: Can't resolve /src/test.ts

I'am trying to run the unit test for my Angular 2 App via: ng test , but I keep getting the following error:我正在尝试通过ng test为我的 Angular 2 应用程序运行单元测试,但我不断收到以下错误:

ERROR in Entry module not found: Error: Can't resolve 

'/Users/username/Dev/dashboard/src/test.ts' in '/Users/username/Dev/dashboard/node_modules/@angular/cli/models/webpack-configs'
28 07 2017 15:18:35.337:WARN [launcher]: Chrome have not captured in 60000 ms, killing.
28 07 2017 15:18:35.441:INFO [launcher]: Trying to start Chrome again (1/2).
28 07 2017 15:19:35.447:WARN [launcher]: Chrome have not captured in 60000 ms, killing.
28 07 2017 15:19:35.587:INFO [launcher]: Trying to start Chrome again (2/2).

The Angular CLI version (after npm update): @angular/cli: 1.2.6 and the Node version is: node: 8.0.0 Angular CLI 版本(npm 更新后): @angular/cli: 1.2.6和 Node 版本是: node: 8.0.0

The other commands: ng build -prod and: ng serve work fine without errors and I can access the app on the browser.其他命令: ng build -prod和: ng serve工作正常,没有错误,我可以在浏览器上访问该应用程序。

One thing I have to mention is that a couple of days ago, I did remove all the .spec.ts files from the folders as all methods:我必须提到的一件事是,几天前,我确实从所有方法中删除了文件夹中的所有.spec.ts文件:

describe(), beforeEach(), it()

couldn't be found.找不到。 After searching, I found that the app wouldn't break when removing them, but today I did create them once again to run the unit test for the app.经过搜索,我发现删除它们时应用程序不会中断,但今天我再次创建它们以运行应用程序的单元测试。

Any idea please?有什么想法吗?

I had the same your problem, what let's me think your test.ts file is missing, here is its content:我和你有同样的问题,我认为你的test.ts文件丢失了,这是它的内容:

// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/proxy.js';
import 'zone.js/dist/sync-test';
import 'zone.js/dist/jasmine-patch';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';
import { getTestBed } from '@angular/core/testing';
import {
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';

// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
declare const __karma__: any;
declare const require: any;

// Prevent Karma from running prematurely.
// tslint:disable-next-line:only-arrow-functions
__karma__.loaded = function () {};

// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);
// Finally, start Karma to run the tests.
__karma__.start();

Just save it in app/src/test.ts and rerun ng test .只需将其保存在app/src/test.ts并重新运行ng test

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ./src/polyfills.ts 中的错误未找到模块:错误:无法解析“zone.js/dist/zone” - ERROR in ./src/polyfills.ts Module not found: Error: Can't resolve 'zone.js/dist/zone' 在Angular 7中获取错误./src/app/app.component.ts找不到模块:错误:无法解析 - Get error in Angular 7 ./src/app/app.component.ts Module not found: Error: Can't resolve Angular 4错误-./src/main.ts中找不到错误:错误:无法解析'./$$_gendir/app/app.app.module.ngfactory' - Angular 4 error - ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' ./src/app/svg.component.ts中的错误找不到模块:错误:无法解析'./svg.component.svg' - ERROR in ./src/app/svg.component.ts Module not found: Error: Can't resolve './svg.component.svg' 错误 in./src/app/app.component.ts 找不到模块:错误:无法解析 './app.component.css' - ERROR in ./src/app/app.component.ts Module not found: Error: Can't resolve './app.component.css' angular - ReferenceError:在http:// localhost:9877src / test.ts中找不到变量:URLSearchParams - angular - ReferenceError: Can't find variable: URLSearchParams in http://localhost:9877src/test.ts ./src/app/component/header.component.ts 模块未找到:错误:无法解析'./header.component.html - ./src/app/component/header.component.ts Module not found: Error: Can't resolve './header.component.html 当广告在我的文件上添加代码,就像在视频上一样时,我得到错误“ ./src/app/app.module.ts找不到模块:错误:无法解析'@ angular / http'” - when ad add code on my file as it is on video i get error “./src/app/app.module.ts Module not found: Error: Can't resolve '@angular/http'” ./src/main/webapp/app/app.main.ts 中的 Jhipster webpack 生产错误,找不到模块:错误:无法解析“./app.module.ngfactory” - Jhipster webpack production ERROR in ./src/main/webapp/app/app.main.ts ,Module not found:Error: Can't resolve './app.module.ngfactory' ./src/main.ts中的ngcli 6.1.3错误-无法解析'./app/app.module.ngfactory' - ngcli 6.1.3 ERROR in ./src/main.ts - Can't resolve './app/app.module.ngfactory'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM