-
Notifications
You must be signed in to change notification settings - Fork 81
Not working in angular2-rc6 and webpack #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
In our team we're trying to import and export
where EDIT Also, if dropping completely ColorPickerModule and just working with plain "old" service and directive, ColorPickerDirective cannot be added to custom module declarations:
and of course not even re-exported, so as soon as some component view uses that, following console error shows up:
|
Any news on this? We're now on the final release of ng2, would be great if this issue could be fixed, because there are A LOT of webpack users out there. Thx! One way to "fix" this. Is just to copy paste the typescript source code into a folder of your own project and just import the ColorPickerModule. Just make sure you have this in your webpack config (or something a like) and the sass-loader and node-sass dep installed
|
@Webtrix yep we were doing the same with a fork of this project: manually copying library source code into our own project subfolder. Having seen recent commits on original library, we opted to switch back to it, but now we're stuck on those errors. |
This should be a valid example of another library being adapted to angular-cli compiler, so to generate metadata files: |
BTW @Webtrix the copy-source-in-place trick does not seem to work for us now. All is fine at build time and when browsing the application. Then when user clicks the field to open color picker popup, the following error shows up in console:
but that doesn't make a lot of sense: the reported component is the root app component, which of course has already been parsed correctly as the application runs already in client. That is the actual original body of page, before angular kicks in. It looks like somehow the DialogComponent tries to "inflate" the whole body again. Maybe it's an issue related to dynamic component creation, don't know really. Or maybe is due to the presence of EDIT this.compiler.compileModuleAndAllComponentsAsync(DynamicCpModule) // <--
.then(factory => { |
I don't use the Angular-CLI since it still has to many issues, certainly when using 3rd party libraries. |
We're not using it either, we're on webpack too. The angular-cli seems to be needed for the author, in order to build the library so to generate metadata files. We copied source code in our project and are getting that error. It looks like dynamic component creation has changed: Equivalent of $compile in Angular 2 We're still on RC7 and get the mentioned error. Does this library currently work for you, when copying its source code? Thanks |
That seems to be strange... I'm using webpack as well and I have had no problems what so ever. I created a folder in my project called "color-picker". I pasted all the files in there (Typescript only of course) and the template folder. Then added the sass-loader and node-sass to my webpack config. And then in my app, I added "ColorPickerModule" in the imports array and that was it, all works fine. |
Thanks. Moved to angular 2 final. Initially had still same issue. Then, after some experiments with webpack CSS loaders, it seems like issue is somehow related to color picker CSS not being correctly included during build phase. If you copied library source code as-is ( |
Until now, the only way we were able to make this work is with this change to color-picker.directive.ts: @Component({
selector: 'color-picker',
//templateUrl: './templates/default/color-picker.html',
//styleUrls: ['./templates/default/color-picker.css']
template: require('./templates/default/color-picker.html'),
styles: [require('./templates/default/color-picker.scss')], // <-- note also extension change
})
// ... and then of course enable dedicated Sass loading in webpack, with following loader: {
test: [/component\.scss$/, /color-picker\.scss$/],
loaders: ['raw-loader', 'postcss-loader', 'sass-loader'],
// ...
} EDIT @Component({
selector: 'color-picker',
templateUrl: './templates/default/color-picker.html',
//styleUrls: ['./templates/default/color-picker.css']
styleUrls: ['./templates/default/color-picker.scss'] // <-- note extension
})
// ... |
Sorry, I'm updating the library very soon. after ->.pipe(inlineNg2Template({base: '/lib'})) in compile task should solve the problem. |
Using angular cli this also fails. I think its due to webpack and barrels. See: angular/angular-cli#1831 Which implies that I tried modifying node_modules/angular2_color_picker/index.ts to:
no luck tho, still the same issue. |
@BrainCrumbz you shouldn't use the .css, but the real source and that's the .scss file indeed. I'll lay out the steps one more time for everybody else.
Run your app, you should be good... |
Just to be clear, the original library source code references CSS, not SCSS: styleUrls: ['./templates/default/color-picker.css'] So it's not that I'm intentionally using CSS. I got that from original source, and had then to change it in order to work. So if you "just" copy the original source, leaving CSS extension, very likely the SCSS loading is not really being involved, probably CSS file is processed by its corresponding loader I guess. |
That's a typo (for webpack users), it needs to point to '.scss' and then it works fine. Because in the template folder, the file itself is a '.scss' file. Since webpack will use the actual path of the file, that isn't there, it's normal it will throw an error. If you're using Gulp or something else, the compiling probably will be done before, so a '.css' variant will be created, and then the path is correct, but in our case it never will be. |
I'm sure author will address that. It's just something to be aware of when you copy library source over to your project. |
@gatapia I'm not sure editing .ts files within node_module package has any effect. Maybe at that point it's the .js one to be picked up, and .ts is basically ignored? |
I added a new release (https://github.com/Alberplz/angular2-color-picker/releases/tag/1.2.1 ) to solve that, also included a webpack example. Sorry not to mention that. |
The library doesn't work with webpack and the angular 2 rc6. It seems like external libraries that are compiled to .js needs to have a metadata.json (https://github.com/orizens/angular2-infinite-scroll/issues/77, ). I'm having the same issue as described here, http://stackoverflow.com/questions/39335621/angular2-metadata-error-when-pre-compiling-feature-module.
The text was updated successfully, but these errors were encountered: