search

Home  >  Q&A  >  body text

angular.js - angular2 Cannot resolve all parameters for 'Parser'(?).

I just built an angular2 framework, angular version 2.4.0, after webpack packaging, the browser console reported an error:
bundle.min.js:39162 Uncaught Error: Cannot resolve all parameters for 'Parser'(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'Parser' is decorated with Injectable.
But if the angular version is changed to 2.0, no error will be reported. The code is also the simplest demo on the official website. The following is the tsconfig.json configuration

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "node_modules",
    "typings/main",
    "typings/main.d.ts"
  ],
  "compileOnSave": false,
  "buildOnSave": false
}

Is it a ts configuration error or some other reason? Please solve

phpcn_u1582phpcn_u15822823 days ago806

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-05-15 17:15:27

    From your error report, it seems that there is something wrong with DI. You can try changing your target to:

    "target": "es6"

    If that doesn’t work, try explicitly introducing the operator into your service:

    import {Inject} from '@angular/core';
    //...
    constructor(@Inject(SomeService) someService: SomeService);

    Hope you can solve it smoothly :)

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-15 17:15:27

    Since you didn’t post the complete code, I can only make a guess:
    It should be that when you called a certain function, you didn’t pass it the parameters required by the function. To give a chestnut:

    function fn(str){
        console.log(str || '参数未定义');
    }
    fn();//参数不正确
    

    Since typescript will also strictly check the parameters of the function, when this code executes fn(), it does not pass the str parameter to fn, so an error will occur during compilation.

    You can learn from other people’s projects to build an angular development environment. Github has many examples of using webpack to build an angular development environment. Here is a more complete and better demo for reference:
    https://github. com/ntesmail/a…

    reply
    0
  • Cancelreply