Netlify Dev Functions

answered
#1

Hey guys I am testing out netlify dev command to test functions locally. I am running into an issue.

Seems like its not recognizing "import"

Actual error:

import fetch from 'node-fetch'
^^^^^^

SyntaxError: Unexpected token import

My function file:

import fetch from 'node-fetch'

exports.handler = async (event, context, callback) => {
  const behanceEndpoint = `https://www.behance.net/v2/users/jhackett1/projects?api_key=${
process.env.BEHANCE_API_KEY
  }`
  const response = await fetch(behanceEndpoint)
  const data = await response.json()
  return {
statusCode: 200,
body: JSON.stringify(data.projects)
  }
}

P.S. How do I setup local variables for dev?

#2

hiya, @talkaboutdesign i am moving this post to #netlify-dev as it belongs there more than here, i think!

#3

correct, netlify dev runs in raw Node.js so no import/export syntax. use require instead, unless you really really need it for some reason, then you can use netlify-lambda.

local variables - you can either use a dotenv type setup, or with netlify dev you can put it in your build environment variables in the app.netlify.com user interface

1 Like