angular: Cannot resolve all parameters for 'Parser'(?). Works 2.3.1, not in 2.4.0. reflect-metadata issue ?
I’m submitting a … (check one with “x”)
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
The bug happens when the application is starting :
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.
By removing some piece of my code, until the bug is no more present, I found it was when I was commenting reflect-metadata
dependency in the webpack
config. The reflect-metadata
version in my project is 0.1.9
.
Expected behavior
The application should start
Minimal reproduction of the problem with instructions
Here the minimal code for the error, while using Cordova
webpack config
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
'app': [
'./src/app/main.ts'
],
'vendor': [
'core-js/client/shim.min.js',
'zone.js/dist/zone',
'@angular/common',
'@angular/compiler',
'@angular/core',
'@angular/http',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'reflect-metadata', //When I comment reflect-metadata, no more error
'rxjs'
]
},
output: {
path: './www',
filename: 'script/[name].js'
},
module: {
loaders: [
{test: /\.ts$/, exclude: /\.component.ts$/, loader: 'ts'},
{test: /\.html$/, loader: 'raw'},
]
},
resolve: {
extensions: ['', '.js', '.ts']
},
plugins: [
new HtmlWebpackPlugin({template: './src/index.html'}),
new webpack.optimize.CommonsChunkPlugin("vendor", "script/vendor.js")
]
};
**main.ts **
import {platformBrowserDynamic} from "@angular/platform-browser-dynamic";
import {BrowserModule} from "@angular/platform-browser";
import {HttpModule} from "@angular/http";
import {NgModule} from "@angular/core";
import {Component} from "@angular/core";
@Component({
selector: 'my-app',
template: '<div>BAR</div>'
})
export class AppComponent {
}
@NgModule({
imports: [
BrowserModule,
HttpModule,
],
declarations: [
AppComponent
],
providers: [
],
bootstrap: [
AppComponent
]
})
export class AppModule { }
const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);
index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Security-Policy" content="default-src *; font-src 'self' data:; img-src 'self' data:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; object-src * 'self' blob:">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
</head>
<body>
<my-app>
FOO
</my-app>
<script type="text/javascript" src="cordova.js"></script>
</body>
</html>
What is the motivation / use case for changing the behavior?
I don’t know
Please tell us about your environment:
Windows 10, yarn/npm, Cordova, Webpack all latest versions
- Angular version: 2.4.0
- Browser: Mobile Chrome XX
- Language: TypeScript 2.1.4
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 19
- Comments: 39 (2 by maintainers)
Angular really is starting to frustrate me. In every minor release since 2.0 something broke in my codebases or in dependent packages (f.e. two times in ng2-redux). Sometimes even a point release broke my builds (f.e. 2.2.2 -> 2.2.3 broke their own router module).
Currently I have to rank angular as a beta software at best, which is really sad.
Yes, problem with the order. You need at first load polyfills.
I put
import 'reflect-metadata'
on the very top of my polyfills and it runs without errorI had this problem too. As was mentioned by @Fost and @aajajim moving the polyfill import to the top of my entry file (main.ts) solved the issue.
My polyfill.ts file:
And my main.ts file
OK so even more success.
I started off without
reflect-metadata
using angular 2.2, webpack2, awesome typescript loader.I had the following folder structure for my entries
My polyfills looked like the following:
vendors.ts
And main.ts
With my webpack config working as it did when I originally upgraded to 2.4.x, I can get it working by installing
reflect-metadata
as a dependency, then not putting it in the polyfills file but putting it at the top of the vendor.ts file.e.g.
It will then work for me.
I’m still not sure entirely why I need
reflect-metadata
as it wasn’t a dependency before, nor is it in the angular 2 webpack tutorial on the main site, which has a similar app, vendor, polyfills setup.I can conform this effect (again, read my initial comment above), ‘core-js/es7/reflect’ breaks angular 2.4.1, works with 2.3.1.
The order of imports does not matter. But replacing it with reflect-metadata solves the issue.
As this breaks an existing dependency (core-js), this is a breaking change and must be fixed. Please reopen.
I think it has to do with the order in which the dependencies are loaded. I had the angular dependencies together with
reflect-metadata
in one bundle. When I pulled outreflect-metadata
into a separate js file and included that first the problem was gone.Error: Cannot resolve all parameters for ‘Parser’(?). i just now upgrade my angular version and i’m using angular@^2.4.8 and same error. i put
import 'reflect-metadata'
top of vendor.ts, it works. i don’t know why…I confirme, it has to do with import order. In my main.ts, i change it to :
import 'angular2-meteor-polyfills';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './imports/app/app.module';
const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);
And it works fine
I’ll add my situation to help clarify a bit. I had the dependency on
reflect-metadata
and oncore-js/es7/reflect
. Removing thereflect-metadata
only seems to work ok (in my situation, very simple app with two routes that display a simple html page). Removing onlycore-js/es7/reflect
or removing both I get the described error.Hope this helps.