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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES modules syntax support? #124

Open
sekhavati opened this issue Jun 3, 2022 · 3 comments
Open

ES modules syntax support? #124

sekhavati opened this issue Jun 3, 2022 · 3 comments

Comments

@sekhavati
Copy link

sekhavati commented Jun 3, 2022

Hello 馃憢 We use TypeScript throughout our projects. Typically we use ES modules syntax (import/export) to load our modules, this then gets boiled down to CommonJS style (require) after the compiler has run.

It seems this module does not support use of the import/export syntax, is it suppose to?

For example we encounter these sorts of errors:

Working example:

const webhooks = require("gocardless-nodejs/webhooks");

webhooks.parse(...); // ok

Broken example:

import webhooks from "gocardless-nodejs/webhooks";

webhooks.parse(...); // => Runtime TypeError: Cannot read properties of undefined (reading 'parse')
@sekhavati sekhavati changed the title import/export support? ES modules support? Jun 9, 2022
@sekhavati sekhavati changed the title ES modules support? ES modules syntax support? Jun 9, 2022
@jacktomlinson
Copy link

Just stumbled across this issue as we are having the same issue - feels strange that a package like this would not support ES Modules syntax 馃

@sohilpandya
Copy link

Hey Both, I'm sure you've solved your issues but this is how you'd go about using the library and get the types support.

import { GoCardlessClient } from 'gocardless-nodejs/client';
import Constants from 'gocardless-nodejs/constants';

// Initialise the client.
const gocardless = new GoCardlessClient(
  SECRET,
  Constants.Environments.Live OR Constants.Environments.Sandbox,
);

@SPH73
Copy link

SPH73 commented Apr 18, 2023

Hey Both, I'm sure you've solved your issues but this is how you'd go about using the library and get the types support.

import { GoCardlessClient } from 'gocardless-nodejs/client';
import Constants from 'gocardless-nodejs/constants';

// Initialise the client.
const gocardless = new GoCardlessClient(
  SECRET,
  Constants.Environments.Live OR Constants.Environments.Sandbox,
);

Hi, Thanks for adding your reply - I've been able to get my integration working with Nuxt 3 locally as a result.

In a dev env, it all works great and a payment journey is completed successfully but when I deploy to Netlify, I get an error at the billing-request action stage which I think maybe it's as a result of importing the package as an ESM module.

Apr 18, 12:52:32 PM: d1f10929 ERROR  [nuxt] [request error] [unhandled] [500] Cannot find module '/var/task/node_modules/gocardless-nodejs/client' imported from /var/task/chunks/billing-request.post.mjs
Did you mean to import gocardless-nodejs/client.js?
  at new NodeError (node:internal/errors:387:5)  
  at finalizeResolution (node:internal/modules/esm/resolve:330:11)  
  at moduleResolve (node:internal/modules/esm/resolve:907:10)  
  at defaultResolve (node:internal/modules/esm/resolve:1115:11)  
  at nextResolve (node:internal/modules/esm/loader:163:28)  
  at ESMLoader.resolve (node:internal/modules/esm/loader:841:30)  
  at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)  
  at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)  
  at link (node:internal/modules/esm/module_job:75:36)

Would you perhaps be able to comment on this and make a suggestion as to what I could try to do to fix it? I contacted their support but I've not had a response.

TIA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants