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

Error while Nordigen node client library on node version > 12.x : Must use import to load ES Module: /../node_modules/nordigen-node/lib/index.js require() of ES modules is not supported. #13

Closed
praji1304 opened this issue Apr 1, 2022 · 8 comments

Comments

@praji1304
Copy link

I am using latest stable node version i.e 16.14.2, I get below mentioned error on compiling the code.

const nordigen_node_1 = require("nordigen-node");
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/polyscripts/polyscripts/payments-backend/node_modules/nordigen-node/lib/index.js from /home/../dist/nordigen/nordigen.controller.js not supported.
Instead change the require of index.js in /home/../dist/nordigen/nordigen.controller.js to a dynamic import() which is available in all CommonJS modules.

@victory-sokolov
Copy link
Collaborator

Hi.

You should use import NordigenClient from "nordigen-node"; instead of require

As well you will need to add "type": "module", to package.json

You can check express example app in the example directory

@praji1304 praji1304 changed the title Node Error while Nordigen node client library on node version > 12.x : Must use import to load ES Module: /../node_modules/nordigen-node/lib/index.js require() of ES modules is not supported. Apr 1, 2022
@praji1304
Copy link
Author

Hi @victory-sokolov ,

Thanks for the quick reply,

I followed the same approach as importing NordigenClient from "nordigen-node". I'am using nestJs and the code I write is in typescript. Hence the error that is being thrown is in the transpiled .js file, that I do not have any control over. 
On doing so I got an error mentioned below:Must use import to load ES Module: /home/../node_modules/nordigen-node/lib/index.js
require() of ES modules is not supported.

Aslo about adding "type": "module" to package.json, on trying that I got an error as attached in the screenshot.
well I surfed on internet for further resolution, but few say index.js should be renamed to index.cjs, but I am not sure how and where that would affect the whole application. 

nordigenIssue

@deyceg
Copy link

deyceg commented Apr 5, 2022

If you want to use commonjs you can run the module through babel and it'll work.

@jans-y
Copy link

jans-y commented Jul 23, 2022

@praji1304 Could you please share your solution? I am still stuck on it. Also using NestJS.

Thanks

@praji1304
Copy link
Author

praji1304 commented Jul 27, 2022

@jans-y did not find any solution that time at least, I ended up implementing the integration with their APIs. It will cost you a few hours but works perfectly fine.

@jan-siroky
Copy link

@praji1304 Thanks for the response. I did the same. Would be nice to either have it fixed or state this into docs as known limitation so devs don't waste their time on this issue ;)

@fstybel
Copy link

fstybel commented Jul 28, 2022

If you want to use commonjs you can run the module through babel and it'll work.

@deyceg Can you explain how to do it?

@victory-sokolov
Copy link
Collaborator

Hello!
Sorry for the delay in response.
You could try to use dynamic-imports to overcome this problem.

Try something like this and let us know if this will works for you

const nordigenNode = await import('nordigen-node');
const NordigenClient = nordigenNode.default;
const client = new NordigenClient({secretId: '', secretKey: ''}); 

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

6 participants