ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

wpapi doesn't work after rollup

Open alamusi opened this issue 10 years ago • 4 comments

Short description of the problem:

wpapi no longer works with RC0

What behavior are you expecting?

Like beta11 and many other beta version, it should work regardless in browsify, webpack, or this new rollup...

Steps to reproduce:

  1. ionic start test blank --v2
  2. npm install --save wpapi
  3. npm install --save util
  4. npm install --save url
  5. npm install --save querystring
  6. npm install --save rollup-plugin-json
  7. add var json = require('rollup-plugin-json');
  8. add json() into rollup.config -> plugins (to satisfy json loading in wpapi)
  9. update extensions: ['.js','.json'], rollup.config -> plugins (to satisfy json loading in wpapi)
  10. add preferBuiltins: false into rollup.config -> plugins -> nodeResolve (to satisfy util, url, and querystring dependency for wpapi)
  11. ionic serve
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from 'ionic-native';

import { HomePage } from '../pages/home/home';

import WPAPI from 'wpapi';

@Component({
  template: `<ion-nav [root]="rootPage"></ion-nav>`
})
export class MyApp {
  rootPage = HomePage;

  constructor(platform: Platform) {
    //WPAPI
    console.log('WPAPI ',WPAPI);
    let wp = new WPAPI({ endpoint: 'http://demo.wp-api.org/wp-json/' });
    wp.posts().then(function( posts ) {
      console.log( posts );
    }).catch(function( err ) {
      console.error( err );
    });

    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      StatusBar.styleDefault();
    });
  }
}

Other information: (e.g. stacktraces, related issues, suggestions how to fix, stackoverflow links, forum links, etc) blank page, no console error or anything.

Which Ionic Version? 1.x or 2.x 2.0 RC0

Run ionic info from terminal/cmd prompt: (paste output below) Cordova CLI: 6.3.1

Ionic Framework Version: 2.0.0-rc.0 Ionic CLI Version: 2.1.0 Ionic App Lib Version: 2.1.0-beta.1 ios-deploy version: Not installed ios-sim version: Not installed OS: Mac OS X El Capitan Node Version: v6.6.0 Xcode version: Xcode 7.3.1 Build version 7D1014

alamusi avatar Sep 30 '16 04:09 alamusi

Hello, thanks for opening an issue with us! The latest release of app-scripts uses webpack by default which will work with older commonJS libraries with no config. To update you can follow the instructions in that blog post.

jgw96 avatar Oct 31 '16 21:10 jgw96

Hello. Sorry to post in the closed issue, but as for now, with RC3, i'm still not able to use WPAPI.

I tried to import the same as the docs:

import * as WPAPI from 'wpapi';

and the same as @alamusi:

import WPAPI from 'wpapi';

When I just import, it works fine, when I try to use the WPAPI in any way, I get the white screen without a clue on what's happening.

Doing the same with moment works just fine. I'm not sure if I'm doing something wrong or that's a real issue.

victorivens05 avatar Nov 27 '16 21:11 victorivens05

I have same issue with @victorivens05

fidoafif avatar Mar 23 '17 06:03 fidoafif

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

ionitron-bot[bot] avatar Sep 03 '18 15:09 ionitron-bot[bot]