Problem with native plugin NativeAudio

I’m trying to use the native Ionic plugin NativeAudio.

I started from a blank Ionic2 project (ionic v2.0.0.0-beta.37), then, as described on


did

ionic plugin add cordova-plugin-nativeaudio

In app.ts I try to import:

import {NativeAudio} from 'ionic-native';

but I get a compilation error

... Error TS2305: Module ".../node_modules/ionic-native/dist/index" has no exported member 'NativeAudio'.

My package.json looks like this:

{
  "dependencies": {
    "@angular/common": "2.0.0-rc.4",
    "@angular/compiler": "2.0.0-rc.4",
    "@angular/core": "2.0.0-rc.4",
    "@angular/platform-browser": "2.0.0-rc.4",
    "@angular/platform-browser-dynamic": "2.0.0-rc.4",
    "@angular/http": "2.0.0-rc.4",
    "@angular/forms": "0.2.0",
    "es6-shim": "0.35.1",
    "ionic-angular": "2.0.0-beta.11",
    "ionic-native": "1.3.10",
    "ionicons": "3.0.0",
    "reflect-metadata": "0.1.8",
    "rxjs": "5.0.0-beta.6",
    "zone.js": "0.6.12"
  },
  ...
  "cordovaPlugins": [
    "cordova-plugin-whitelist",
    "cordova-plugin-statusbar",
    "cordova-plugin-console",
    "cordova-plugin-device",
    "cordova-plugin-splashscreen",
    "ionic-plugin-keyboard",
    "cordova-plugin-nativeaudio"
  ],
 ...
}

Where did I go wrong?

I’m not sure as to the why of the issue, but it appears that you’re using an older Ionic Native. The NativeAudio plugin was added in 1.3.14.

So I’d update your package.json to point to the latest Ionic Native (which as of right now would be 1.3.21) and then run npm install.

I don’t know how I got an older Ionic Native, but upgrading it solved the problem!
Thank you!