刚搭建一个angular2的框架,angular版本2.4.0,webpack打包完浏览器console报错:
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.
但是angular版本改为2.0的就不会报错,代码也是最简单的官网上的demo,以下是tsconfig.json配置
{
"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
}
是ts配置出错还是什么原因呢,求解
From your error report, it seems that there is something wrong with DI. You can try changing your
target
to:If that doesn’t work, try explicitly introducing the operator into your service:
Hope you can solve it smoothly :)
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:
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…