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

require node-fetch is throw error “ syntax error ” #1230

Closed
Hooho opened this issue Jul 30, 2021 · 3 comments
Closed

require node-fetch is throw error “ syntax error ” #1230

Hooho opened this issue Jul 30, 2021 · 3 comments
Labels

Comments

@Hooho
Copy link

Hooho commented Jul 30, 2021

No description provided.

@Hooho Hooho added the question label Jul 30, 2021
@Hooho
Copy link
Author

Hooho commented Jul 30, 2021

image

I know import is not supported in node,so it is a syntax error,but why not-fetch will use it?

So What can I do to require this pkg?

@Hooho Hooho changed the title When require node-fetch is throw error “ syntax error ” Jul 30, 2021
@jimmywarting
Copy link
Collaborator

I suspect you are trying out node-fetch@v3.0.0-beta.10 we converted our package to use only ESM syntax
we no longer support cjs and switched to using import/export instead

I know import is not supported in node,so it is a syntax error,but why not-fetch will use it?

I guess you are wrong. imports have been supported in nodejs ever since v12.20 (with top level await in v14 or something like that)
So here is what you have to do:

  1. Update and use a newer nodejs version that is 12.20 or higher
  2. Change package.json to include a "type": "module"
  3. use import fetch from 'node-fetch'
    or alternative use import('node-fetch') if you are stuck with using cjs

@jimmywarting
Copy link
Collaborator

Locking b/c it's nicer to keep the discussion in one place.
(We still keep a open mind and looking for a solution - it dose not mean we will overlook this Issue)

Feel free to keep the discussion in #1227 where most of the discussion is already happening

@node-fetch node-fetch locked and limited conversation to collaborators Aug 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants