skip to Main Content

Below are the two error (image) I’m facing
I’m using Ionic 4.
everything works but as soon I start calling WooCommerce API and use it in constructor I get the below two errors.

I have imported Woocommerce API, but when I initialize it in constructr it shows enter image description hereboth of this error.enter image description here

2

Answers


  1. It looks like you are using this package which has an obsolete warning:

    • 2019-07-29: This client is obsolete and will no longer receive updates, a new JavaScript library is available under the name of @woocommerce/woocommerce-rest-api.

    However, that’s a node.js package. It’s failing because fs stands for filesystem and that doesn’t exist in the browser.

    Node.js is for local development, not for browser packages, which is what Ionic 4 is built with.

    However, if you really want to use it then this guide will show you how to wrap it up using browserify:

    Transforming a Node.js Module to A Browser Library

    The solution is to use Browserify to bundle the module with all its dependencies inside one JavaScript file so we will not need any external Node.js dependencies which are not available inside the Cordova webview (a headless browser) used by Ionic 4.

    https://www.techiediaries.com/woocommerce-ionic-2/

    I don’t know how far you’ll get as it’s for Ionic 2 but I’m just showing you this to demonstrate that node.js packages are not for Ionic.

    Update

    Based on your comments you say you are having problems with global not being defined.

    Searching Google this seems to be a solved issue, try:

    I think for now the best option would be to include

    (window as any).global = window;

    In your polyfills.ts file, as mentioned here:
    angular/angular-cli#9827 (comment)

    Login or Signup to reply.
  2. You have to go to folder node_modules@angular-devkitbuild-angularsrcangular-cli-filesmodelswebpack-configsbrowser.js and replace node: false, by node: { crypto: true, stream: true, fs: "empty", net: "empty", tls: "empty" },
    It’s working for me.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search