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

node-fetch update causing errors #145

Open
upkarlidder opened this issue Feb 16, 2022 · 3 comments
Open

node-fetch update causing errors #145

upkarlidder opened this issue Feb 16, 2022 · 3 comments
Assignees
Labels
bug Something isn't working dependencies Pull requests that update a dependency file
Milestone

Comments

@upkarlidder
Copy link
Member

upkarlidder commented Feb 16, 2022

Is your feature request related to a problem? Please describe.

node --version         
v16.14.0

npm --version
8.3.1

Dependabot updated node-fetch from 2.x to 3.x. This causes the following error when running yarn run start-ui

[2022-02-16T10:02:02.057] [INFO] appid-WebAppStrategy-config - redirectUri http://localhost:3000/ibm/cloud/appid/callback
/Pyrrha-Dashboard/pyrrha-dashboard/api-auth/services/appId.js:1
const fetch = require('node-fetch');
              ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Pyrrha-Dashboard/pyrrha-dashboard/api-auth/node_modules/node-fetch/src/index.js from /Pyrrha-Dashboard/pyrrha-dashboard/api-auth/services/appId.js not supported.
Instead change the require of index.js in /Pyrrha-Dashboard/pyrrha-dashboard/api-auth/services/appId.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Pyrrha-Dashboard/pyrrha-dashboard/api-auth/services/appId.js:1:15)
    at Object.<anonymous> (/Pyrrha-Dashboard/pyrrha-dashboard/api-auth/rest/routes.js:5:25)
    at Object.<anonymous> (/Pyrrha-Dashboard/pyrrha-dashboard/api-auth/server.js:11:16) {
  code: 'ERR_REQUIRE_ESM'

Describe the solution you'd like
The error is documented here - https://github.com/node-fetch/node-fetch#commonjs

node-fetch from v3 is an ESM-only module - you are not able to import it with require().

If you cannot switch to ESM, please use v2 which remains compatible with CommonJS. Critical bug fixes will continue to be published for v2.

Alternatively, you can use the async import() function from CommonJS to load node-fetch asynchronously

We can also look at other libraries like axios.

Describe alternatives you've considered
N/A

Additional context
Add any other context or screenshots about the feature request here.

@upkarlidder upkarlidder added bug Something isn't working dependencies Pull requests that update a dependency file labels Feb 16, 2022
@upkarlidder upkarlidder added this to the Milestone1 milestone Feb 16, 2022
@krook
Copy link
Member

krook commented Feb 28, 2022

Is this now resolved by reverting to an older version @upkarlidder?

@upkarlidder
Copy link
Member Author

Yes. That was the quick fix. Need to check if there are any security issues with the lower version. What got fixed in the next version and if we need to move up.

@krook
Copy link
Member

krook commented Mar 25, 2022

Any update on this one @upkarlidder?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Pull requests that update a dependency file
Projects
None yet
Development

No branches or pull requests

2 participants