Skip to content

Netlify cannot find package in dev #4534

@NicoleJaneway

Description

@NicoleJaneway

Describe the bug

I have my backend lambdas in a functions/ folder. One of them (mailchimp.js) is set up like this:

require("dotenv").config();

const mc = require("@mailchimp/mailchimp_marketing");

const apiKey = process.env.MAILCHIMP_API_KEY;

mc.setConfig({
  apiKey: apiKey,
  server: "us8",
});

exports.handler = async function (event, context) { ... }

Which results in:

{“errorMessage”:“Cannot set properties of undefined (setting ‘setConfig’)”

I've tried also just pasting in my api key as a string from the .env file with the same result. What is happening here? The function is acting like @mailchimp/mailchimp_marketing is undefined.

@mailchimp/mailchimp_marketing is in dependencies in package.json and everything's been npm installed.

My sample repo (not the exact one I'm deploying but pretty close) is here: https://github.com/NicoleJaneway/netlify-build

Steps to reproduce

  1. Run netlify dev
  2. Open http://localhost:8888/apitest
  3. Hit "Test Mailchimp" button with network tab open

Configuration

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

[[headers]]
for = "/*"
  [headers.values]
  Access-Control-Allow-Origin = "*"
  
[build]
  functions = "functions" # netlify dev uses this directory to scaffold and serve your functions
  publish = "build"

[dev]
  command = "npm run start"
  port = 8888
  targetPort = 3000
  publish = "dist" 
  autoLaunch = true
  framework = "create-react-app"

[functions]
  directory = "functions"
  included_files = ["./src/data/payments.json"]

Environment

System:
OS: macOS 12.1
CPU: (4) x64 Intel(R) Core(TM) i7-5650U CPU @ 2.20GHz
Memory: 140.12 MB / 8.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
Yarn: 1.22.17 - /usr/local/bin/yarn
npm: 8.5.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
npmPackages:
netlify-cli: ^9.16.6 => 9.16.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugcode to address defects in shipped code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions