To use import or require for importing node-fetch for Netlify Serverless Functions? Both give errors

Hi @ronnlidd

Now that node_bundler = "esbuild" is set in the neltify.toml you can/need to change
from:

const fetch = require('node-fetch')

to:

import fetch from 'node-fetch'

This is covered in this post which takes information directly from the npm package page under the section: Loading and configuring the module.

2 Likes