I am currently attempting to transpile my Angular 6 project, which is written in TypeScript, using the new Babel 7. However, I am facing challenges with getting dependency injection to function properly.
Every time I try to launch the project in Chrome, I encounter the following error:
Uncaught Error: Can't resolve all parameters for AppComponent: (?).
at syntaxError (compiler.js:1270)
at CompileMetadataResolver._getDependenciesMetadata (compiler.js:11171)
at CompileMetadataResolver._getTypeMetadata (compiler.js:11064)
at CompileMetadataResolver.getNonNormalizedDirectiveMetadata (compiler.js:10683)
at CompileMetadataResolver._getEntryComponentMetadata (compiler.js:11267)
at eval (compiler.js:10927)
at Array.map (<anonymous>)
at CompileMetadataResolver.getNgModuleMetadata (compiler.js:10927)
at JitCompiler._loadModules (compiler.js:24104)
at JitCompiler._compileModuleAndComponents (compiler.js:24085)
To demonstrate the issue, I have created a fork of a boilerplate and added a simple httpClient service injection: https://github.com/gnihi/angular-6-with-babel-typescript
If I remove the constructor from app.component.ts, everything functions as expected.
Below are the dependencies of the project:
{
"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-proposal-decorators": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"@babel/preset-typescript": "^7.1.0",
"babel-loader": "^8.0.0",
"babel-plugin-transform-decorators": "^6.24.1",
"webpack": "^4.17.1",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.7"
},
"scripts": {
"build:dev": "webpack --mode development",
"build:prod": "webpack --mode production",
"dev": "webpack-dev-server --mode development --content-base=./dist/",
"type-check": "tsc"
},
"dependencies": {
"@angular/common": "^6.1.6",
"@angular/compiler": "^6.1.6",
"@angular/core": "^6.1.6",
"@angular/platform-browser-dynamic": "^6.1.6",
"@angular/platform-browser": "^6.1.6",
"core-js": "^2.5.7",
"zone.js": "^0.8.26"
}
}
Your assistance and guidance are greatly appreciated. Thank you!