无法解析ApplicationModule的所有参数:(?) [英] Can't resolve all parameters for ApplicationModule: (?)

查看:187
本文介绍了无法解析ApplicationModule的所有参数:(?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将应用程序模块迁移为可导入库.

I just migrated an application module to be an importable library.

我正尝试使测试正常工作,就像以前一样,但是出现此错误:

I'm trying to make the tests work correctly, just as they worked before, but I get this error:

Error: Can't resolve all parameters for ApplicationModule: (?).
at syntaxError (webpack:///C:/Repositories/MyProject/my-library/node_modules/@angular/compiler/fesm5/compiler.js?:1275:17)
at CompileMetadataResolver._getDependenciesMetadata (webpack:///C:/Repositories/MyProject/my-library/node_modules/@angular/compiler/fesm5/compiler.js?:11176:35)
at CompileMetadataResolver._getTypeMetadata (webpack:///C:/Repositories/MyProject/my-library/node_modules/@angular/compiler/fesm5/compiler.js?:11069:26)
at CompileMetadataResolver.getNgModuleMetadata (webpack:///C:/Repositories/MyProject/my-library/node_modules/@angular/compiler/fesm5/compiler.js?:10937:24)
at CompileMetadataResolver.getNgModuleSummary (webpack:///C:/Repositories/MyProject/my-library/node_modules/@angular/compiler/fesm5/compiler.js?:10747:35)
at eval (webpack:///C:/Repositories/MyProject/my-library/node_modules/@angular/compiler/fesm5/compiler.js?:10861:51)
at Array.forEach (<anonymous>)
at CompileMetadataResolver.getNgModuleMetadata (webpack:///C:/Repositories/MyProject/my-library/node_modules/@angular/compiler/fesm5/compiler.js?:10849:49)
at CompileMetadataResolver.getNgModuleSummary (webpack:///C:/Repositories/MyProject/my-library/node_modules/@angular/compiler/fesm5/compiler.js?:10747:35)
at eval (webpack:///C:/Repositories/MyProject/my-library/node_modules/@angular/compiler/fesm5/compiler.js?:10861:51)

我已经看到了以下可能的解决方案: 错误:无法解析ApplicationModule的所有参数:(?)无法解析ApplicationModule的参数:(?),但它们不能解决我的问题.

I've seen these possible solutions: Error: Can't resolve all parameters for ApplicationModule: (?) and Cannot resolve parameters for ApplicationModule: (?) but they cannot fix my problem.

projects/my-library/src/test.ts

// This file is required by karma.conf.js and loads recursively all the .spec and framework files

import { getTestBed } from '@angular/core/testing';
import {
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';
import 'zone.js/dist/zone-testing';

declare const require: any;

// 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);

让我知道您是否需要更多信息来找出问题所在.

Let me know if you need more information to figure out where is the problem.

推荐答案

最后,我找到了问题所在,但由于没有相关性,我很难找到它.问题来自此tslint配置:

At last, I found where the problem was, I had a hard time finding it because it was not related. The problem comes from this tslint configuration:

tslint.json :

...
"ordered-imports" [
  true,
  { "named-imports-order": "lowercase-last" }
]
...

即使配置仅为"ordered-imports": true,它也会在启动ng lint时在test.ts文件中引起问题,所以我更改了该文件以满足tslint要求:

Even if the configuration is only "ordered-imports": true it was causing a problem in test.ts file when ng lint is launched, so I changed that file to fulfill the tslint requirement:

test.ts :

// This file is required by karma.conf.js and loads recursively all the .spec and framework files

import { getTestBed } from '@angular/core/testing';
import {
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
import 'core-js/es7/reflect'; // <-- Moved from the top of imports
import 'zone.js/dist/zone'; // <-- Moved from the top of imports
import 'zone.js/dist/zone-testing'; // <-- Moved from the top of imports

declare const require: any;

// 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);

此文件引起了我得到的错误.该文件必须如下所示:

And this file was causing the error I was getting. This file must look like this:

更正 test.ts :

import 'core-js/es7/reflect';
import 'zone.js/dist/zone';
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';

declare const require: any;

// 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);

这篇关于无法解析ApplicationModule的所有参数:(?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆