Integrating D3 with Angular-cli
<p>I am trying to integrate D3 chart library with Angular CLI. First I installed d3 with <strong>npm install d3 --save</strong>. Once done my node_modules looks like</p>

<p><a href="https://i.stack.imgur.com/wH1A9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wH1A9.png" alt="It added following highlighted folders to node_modules folder"></a></p>

<p>d3 version is <strong>"d3": "^4.2.2"</strong>.</p>

<p>Then I set up configuration as below.</p>

<p><strong>angular-cli-build.js</strong></p>

<pre><code>    var Angular2App = require('angular-cli/lib/broccoli/angular2-app');

    module.exports = function(defaults) {
      return new Angular2App(defaults, {
        vendorNpmFiles: [
          ......
          'd3/**/*'
        ]
      });
    };
</code></pre>

<p><strong>system-config.ts</strong></p>

<pre><code>    "use strict";

    // SystemJS configuration file, see links for more information
    // https://github.com/systemjs/systemjs
    // https://github.com/systemjs/systemjs/blob/master/docs/config-api.md

    /***********************************************************************************************
     * User Configuration.
     **********************************************************************************************/
    /** Map relative paths to URLs. */
    const map:any = {
      '@angular2-material': 'vendor/@angular2-material',
      // 'd3': 'vendor/d3'
      'd3': 'vendor/d3/build'
    };

    /** User packages configuration. */
    const materialPackages:string[] = [
      'core',
      'button',
      'icon',
      'sidenav',
      'toolbar',
      'list',
      'card'
    ];
    const packages:any = {
      'd3': {
        format: 'cjs',
        defaultExtension: 'js',
        main: 'd3'
      },
    };
    materialPackages.forEach(name =&gt; {
      packages[`@angular2-material/${name}`] = {
        format: 'cjs',
        defaultExtension: 'js',
        main: name
      };
    });

    ////////////////////////////////////////////////////////////////////////////////////////////////
    /***********************************************************************************************
     * Everything underneath this line is managed by the CLI.
     **********************************************************************************************/
    const barrels:string[] = [
      // Angular specific barrels.
      '@angular/core',
      '@angular/common',
      '@angular/compiler',
      '@angular/forms',
      '@angular/http',
      '@angular/router',
      '@angular/platform-browser',
      '@angular/platform-browser-dynamic',

      // Thirdparty barrels.
      'rxjs',

      // App specific barrels.
      'app',
      'app/shared',
      'app/bar',
      'app/chart',
      /** @cli-barrel */
    ];

    const cliSystemConfigPackages:any = {};
    barrels.forEach((barrelName:string) =&gt; {
      cliSystemConfigPackages[barrelName] = {main: 'index'};
    });



    /** Type declaration for ambient System. */
    declare var System:any;

    // Apply the CLI SystemJS configuration.
    System.config({
      map: {
        '@angular': 'vendor/@angular',
        'rxjs': 'vendor/rxjs',
        'main': 'main.js',
      },
      packages: cliSystemConfigPackages
    });

    // Apply the user's configuration.
    System.config({map, packages});
</code></pre>

<p>In <strong>app.module.ts</strong>, I imported d3 as below.</p>

<pre><code>import * as d3 from 'd3';
</code></pre>

<p>Then,</p>

<pre><code>    @NgModule({
      declarations: [AppComponent, d3],
      providers: [],
      imports: [],
      bootstrap: [AppComponent],
    })
</code></pre>

<p>Following is what my <strong>dist</strong> folder looks,</p>

<p><a href="https://i.stack.imgur.com/hrSog.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hrSog.png" alt="enter image description here"></a></p>

<p>When I try to build the project with <strong>ng build</strong> it gives below error.</p>

<pre><code> Cannot find module 'd3'
</code></pre>

<p>Any suggestions are highly appreciated.</p>

<p>Thank You </p>