Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RIPE SDK not compatible with Nuxt.js under Vercel #195

Closed
gcandal opened this issue Aug 27, 2020 · 1 comment · Fixed by #201
Closed

RIPE SDK not compatible with Nuxt.js under Vercel #195

gcandal opened this issue Aug 27, 2020 · 1 comment · Fixed by #201
Assignees
Labels
bug Something isn't working p-medium Medium priority issue unit-testing Issue requires creation of unit tests

Comments

@gcandal
Copy link
Contributor

gcandal commented Aug 27, 2020

Description

It's not possible to use the RIPE SDK with Nuxt.js when building the application with --standalone, which is done by Vercel. Accessing the page where RIPE SDK is imported results in:

 ERROR  window is not defined                                                                                                                                                                                                                                                            09:18:03

  at Object.<anonymous> (node_modules/ripe-sdk/src/js/base/compat.js:83:0)
  at __webpack_require__ (webpack/bootstrap:25:0)
  at Object.<anonymous> (node_modules/ripe-sdk/src/js/base/api.js:11:0)
  at __webpack_require__ (webpack/bootstrap:25:0)
  at Object.<anonymous> (node_modules/ripe-sdk/src/js/base/index.js:1:0)
  at __webpack_require__ (webpack/bootstrap:25:0)
  at Object.<anonymous> (node_modules/ripe-sdk/src/js/api/account.js:9:0)
  at __webpack_require__ (webpack/bootstrap:25:0)
  at Object.<anonymous> (node_modules/ripe-sdk/src/js/api/index.js:1:0)
  at __webpack_require__ (webpack/bootstrap:25:0)


 ERROR  Cannot read property 'a' of undefined                                                                                                                                                                                                                                            09:18:03

  at Module.ReportHermesLeatherGoods (pages/hermes_leather.js:11360:145)
  at c (node_modules/vue/dist/vue.runtime.common.prod.js:6:0)
  at Tt (node_modules/vue/dist/vue.runtime.common.prod.js:6:0)
  at Function.Cn.t.extend (node_modules/vue/dist/vue.runtime.common.prod.js:6:0)
  at sanitizeComponent (.nuxt/utils.js:74:0)
  at server.js:14522:41
  at async Promise.all (index 0)
  at async getRouteData (.nuxt/utils.js:131:0)
  at async Promise.all (index 0)
  at async setContext (.nuxt/utils.js:214:0)

This is caused by the "environment" detection part not being ready to this use case:

if (
    typeof require !== "undefined" &&
    (typeof window === "undefined" || typeof __webpack_require__ !== "undefined") && // eslint-disable-line camelcase
    typeof XMLHttpRequest === "undefined" // eslint-disable-line no-use-before-define
) {
    var XMLHttpRequest = null;
    if (
        // eslint-disable-next-line camelcase
        typeof __webpack_require__ === "undefined" &&
        (typeof navigator === "undefined" || navigator.product !== "ReactNative")
    ) {
        // this is an hack to work around metro's (react-native bundler)
        // static analysis, needed until it supports optional imports
        // (https://github.com/react-native-community/discussions-and-proposals/issues/120)
        const mixedModuleName = "Xmlhttprequest";
        const correctModuleName = mixedModuleName.toLowerCase();
        XMLHttpRequest = require(correctModuleName).XMLHttpRequest;
    } else {
        XMLHttpRequest = window.XMLHttpRequest;
    }
}

The values at play here are:

  • require is defined
  • __webpack_require__ is defined
  • window is NOT defined
  • XMLHttpRequest is NOT defined

Even though require is available and would be able to import XMLHttpRequest, the code is ending up in XMLHttpRequest = window.XMLHttpRequest; which throws an error.

Expected vs. Observed

- -
Expected Be able to import RIPE SDK.
Observed Importing RIPE SDK throws an error.

Repro Steps

  1. Using Nuxt.js, import RIPE SDK in one of the components
  2. Build the application with nuxt build --standalone
  3. Serve the generated files with nuxt start
  4. Make a request to the page where RIPE SDK is being imported
@gcandal gcandal added the bug Something isn't working label Aug 27, 2020
@joamag joamag added p-medium Medium priority issue unit-testing Issue requires creation of unit tests labels Aug 27, 2020
@joamag joamag assigned gcandal and unassigned joamag Aug 27, 2020
@joamag
Copy link
Contributor

joamag commented Aug 27, 2020

Go for it!

@gcandal gcandal assigned BeeMargarida and unassigned gcandal Sep 28, 2020
joamag added a commit that referenced this issue Oct 9, 2020
#195: RIPE SDK compatibility with Nuxt.js under Vercel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p-medium Medium priority issue unit-testing Issue requires creation of unit tests
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants