There is always a problem with setting up an external project in Angular2.
I want to include ng2-sharebuttons in my project. (which does not appear to have a global .d.ts
file?)
Although README.md
just says npm install ng2-sharebuttons --save
, I know there is something else ( systemjs.config
& typings
)
First I tried to configure systemjs.config
:
map{ ...... 'ng2-sharebuttons' : 'node_modules/ng2-sharebuttons' }
This at least fixed 404
on localhost/ng2-sharebuttons
, but created a new 404
on localhost/node_modules/ng2-sharebuttons
.
So, I added the main file, changing systemjs.config
to
map{ ...... 'ng2-sharebuttons' : 'node_modules/ng2-sharebuttons/dist/index.js' }
But now this results in a 404
for each ng2-sharebuttons/dist
child
I tried typings install ng2-sharebuttons --save --global
and typings install @types/ng2-sharebuttons --save --global
with or without the --global
flag.
So, on my last hope, I added a link to see if this would work. Adding
/// <reference path="../../node_modules/ng2-sharebuttons/dist/index.d.ts" />
But that didn’t change anything.
What did I forget? Why is it so hard? (Or am I just doing it hard?)
The structure and files of ng2-sharebuttons
:
And finally, the error message that Chrome is currently producing:
The whole systemjs.config.js
/** * System configuration for Angular 2 samples * Adjust as necessary for your application needs. */ (function (global) { System.config({ paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { // our app is within the app folder app: 'app', // angular bundles '@angular/core': 'npm:@angular/core/bundles/core.umd.js', '@angular/common': 'npm:@angular/common/bundles/common.umd.js', '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js', '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js', '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js', '@angular/http': 'npm:@angular/http/bundles/http.umd.js', '@angular/router': 'npm:@angular/router/bundles/router.umd.js', '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js', // other libraries 'rxjs': 'npm:rxjs', 'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js', 'angularfire2' : 'npm:angularfire2/bundles/angularfire2.umd.js', 'firebase' : 'npm:firebase', 'ng2-bs3-modal': 'npm:ng2-bs3-modal', 'ng2-sharebuttons' : 'npm:ng2-sharebuttons/dist/index.js', 'ng2-social-share' : 'npm:ng2-social-share/bundles/ng2-social-share.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { app: { main: './main.js', defaultExtension: 'js' }, rxjs: { defaultExtension: 'js' }, firebase: { main: './firebase-browser.js', defaultExtension: 'js' } } }); })(this);
It throws an error GET .... 404
, as well as XHR finished loading: GET ....
in the same component / service / file, which seems rather strange.