本文介绍了'未捕获错误:从Angular 4升级到5.0.1时无法解析'运行时错误的所有参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这在Angular 4.x中很好,而不是Angular 5.0.1。该项目是使用Angular CLI生成的。

This is fine in Angular 4.x, just not Angular 5.0.1. This project was generated with Angular CLI.

compiler.js:466 Uncaught Error: Can't resolve all parameters for RegistrationService: (?).
    at syntaxError (compiler.js:466)
    at CompileMetadataResolver._getDependenciesMetadata (compiler.js:15546)
    at CompileMetadataResolver._getTypeMetadata (compiler.js:15381)
    at CompileMetadataResolver._getInjectableMetadata (compiler.js:15361)
    at CompileMetadataResolver.getProviderMetadata (compiler.js:15721)
    at eval (compiler.js:15632)
    at Array.forEach (<anonymous>)
    at CompileMetadataResolver._getProvidersMetadata (compiler.js:15592)
    at CompileMetadataResolver.getNgModuleMetadata (compiler.js:15160)
    at CompileMetadataResolver.getNgModuleSummary (compiler.js:14998)
syntaxError @ compiler.js:466
CompileMetadataResolver._getDependenciesMetadata @ compiler.js:15546
CompileMetadataResolver._getTypeMetadata @ compiler.js:15381
CompileMetadataResolver._getInjectableMetadata @ compiler.js:15361
CompileMetadataResolver.getProviderMetadata @ compiler.js:15721
(anonymous) @ compiler.js:15632
CompileMetadataResolver._getProvidersMetadata @ compiler.js:15592
CompileMetadataResolver.getNgModuleMetadata @ compiler.js:15160
CompileMetadataResolver.getNgModuleSummary @ compiler.js:14998
(anonymous) @ compiler.js:15086
CompileMetadataResolver.getNgModuleMetadata @ compiler.js:15071
JitCompiler._loadModules @ compiler.js:33486
JitCompiler._compileModuleAndComponents @ compiler.js:33447
JitCompiler.compileModuleAsync @ compiler.js:33363
CompilerImpl.compileModuleAsync @ platform-browser-dynamic.js:230
PlatformRef.bootstrapModule @ core.js:5446
(anonymous) @ main.ts:12
../../../../../src/main.ts @ main.bundle.js:640
__webpack_require__ @ inline.bundle.js:55
1 @ main.bundle.js:670
__webpack_require__ @ inline.bundle.js:55
webpackJsonpCallback @ inline.bundle.js:26
(anonymous) @ main.bundle.js:1

这是构造函数的样子:

     constructor(
    private apiHelperService: ApiHelperService
  ) {
  }

该类有@Injectable()

The class has @Injectable()

    @Injectable()
export class ApiHelperService {

它也已正确导入模块提供程序。

It has also properly imported into the module providers.

providers: [
    AuthGuard,
    ApiHelperService,

如果我将其更改为此,那么错误就会消失并且可以正常工作,但是它希望您将整个解决方案中的每个构造函数都更改为此语法,我不相信为了正确。

If I change it to this, then the error goes away and it works, but then it wants you to change every constructor in the entire solution to this syntax, which I don't believe to be correct.

@Inject(ApiHelperService) private apiHelperService: ApiHelperService

这是我的tsconfig.json,它确实将emitDecoratorMetadata设置为true

Here is my tsconfig.json, which does have emitDecoratorMetadata properly set to true

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "baseUrl": "src",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}


推荐答案

在作者提到他们使用静态注入器而不是基于反射的注入器,并提到不再需要反射polyfill但就我而言,它是。

In Angular 5 Update blog post the author mentions that they are using a static injector instead of a reflection based one and mentions that the reflection polyfills are no longer needed but in my case it was.

如果您删除了反射效果,请尝试重新添加:

If you removed the polyfills for reflections try adding them again:

import 'core-js/es6/reflect';
import 'core-js/es7/reflect';

我希望你也能为它做好准备。

I hope it woks for you as well.

这篇关于'未捕获错误:从Angular 4升级到5.0.1时无法解析'运行时错误的所有参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 02:04