-1

I'm trying to figure out how to import this library into my angular 2 application.

I've tried many things but can't seem to get it to work. Below is my partial systemjs.config.js

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
        .... // Removed to conserve space
        // other libraries
        'rxjs':                      'npm:rxjs',
        'angular-in-memory-web-api': 'npm:angular-in-memory-web-api',
        'youtube-dl':                'npm:youtube-dl'
    },
    // 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'
        },
        'angular-in-memory-web-api': {
            main: './index.js',
            defaultExtension: 'js'
        },
        'youtube-dl': {
            main: './lib/youtube-dl.js',
            defaultExtension: 'js'
        }
    }

This is how I'm trying to import it into my video.service.ts

import * as youtubedl from 'youtube-dl';

I seem to always result into this error

app/service/video.service.ts(2,28): error TS2307: Cannot find module 'youtube-dl'.

Below is my package.json

{
    ...,
    ...,
    ...,
    "dependencies": {
        "@angular/common": "~2.0.1",
        "@angular/compiler": "~2.0.1",
        "@angular/core": "~2.0.1",
        "@angular/forms": "~2.0.1",
        "@angular/http": "~2.0.1",
        "@angular/platform-browser": "~2.0.1",
        "@angular/platform-browser-dynamic": "~2.0.1",
        "@angular/router": "~3.0.1",
        "@angular/upgrade": "~2.0.1",

        "angular-in-memory-web-api": "~0.1.1",
        "core-js": "^2.4.1",
        "reflect-metadata": "^0.1.8",
        "rxjs": "5.0.0-beta.12",
        "systemjs": "0.19.39",
        "zone.js": "^0.6.25",

        "bootstrap": "^4.0.0-alpha.2",
        "font-awesome": "^4.6.1",
        "youtube-dl": "1.11.1"
      },
      "devDependencies": {
          "concurrently": "^3.0.0",
          "electron": "1.4.2",
          "typescript": "^2.0.3",
          "typings":"^1.4.0"
      }
}

Did a npm ls and did see youtube-dl@1.11.1 listed as well

Mike
  • 826
  • 11
  • 31
  • Can't you import it as a node dependency? Seems like you're already making use of it. – Makoto Nov 27 '16 at 02:58
  • It doesn't seem to work, whatever I try results into this error. app/service/video.service.ts(2,28): error TS2307: Cannot find module 'youtubedl'. – Mike Nov 27 '16 at 03:06
  • You should edit your question and include that information. If you can't use NPM that's something that's notable. Also, include your package.json with that attempt. – Makoto Nov 27 '16 at 03:07
  • Thanks, I did some edits hope it helps you and me – Mike Nov 27 '16 at 03:15

1 Answers1

0

The error message saying you need to import youtube module in your app module. Its showing error when it does not find that module

make sure you added the youtube module in your appModle in app.module.ts import list

@NgModule({
  bootstrap: [App],
  declarations: [
    App
  ],
  imports: [ // import Angular's modules
    BrowserModule,
    HttpModule,
    routing
    youtube-...  //your youtube module
  ],
Aniruddha Das
  • 20,520
  • 23
  • 96
  • 132
  • Hi Aniruddha, thanks for the suggestion, I added it to my app.module.ts import list and it no throws these errors. app/app.module.ts(12,28): error TS2307: Cannot find module 'youtube-dl'. app/service/video.service.ts(2,28): error TS2307: Cannot find module 'youtube-dl'. This is how I had it imported `import * as youtubedl from 'youtube-dl';` and `imports: [BrowserModule, youtubedl],` – Mike Nov 27 '16 at 03:51