I posted a longer thread over on discourse regardi...
# help
I posted a longer thread over on discourse regarding this but am cross posting shorter version here in case slack is preferred for help. I have a lambda function that runs fine during local live development but fails when deployed to AWS. I'm using the mailchimp node module which is a client to their web services. It's not an es module but i'm importing it like this:
Copy code
import mailchimp from "@mailchimp/mailchimp_marketing";
When I run the lambda on AWS I get the following error:
Copy code
"errorType": "TypeError",
    "errorMessage": "Cannot set property 'setConfig' of undefined",
    "stack": [
        "TypeError: Cannot set property 'setConfig' of undefined",
        "    at /var/task/src/test.js:7:245570",
        "    at /var/task/src/test.js:1:249",
        "    at /var/task/src/test.js:7:249760",
        "    at /var/task/src/test.js:1:249",
        "    at Object.<anonymous> (/var/task/src/test.js:7:249825)",
        "    at Module._compile (internal/modules/cjs/loader.js:1085:14)",
        "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)",
        "    at Module.load (internal/modules/cjs/loader.js:950:32)",
        "    at Function.Module._load (internal/modules/cjs/loader.js:790:12)",
        "    at Module.require (internal/modules/cjs/loader.js:974:19)"
The line that fails is not in my own function code, but the included mailchimp source that's transpiled into the lambda at the top. Other node modules I'm using work fine. Is this an issue with the mailchimp module or some bug in the transpile? Again, it all works fine during live development. I'm running version
Thanks for any help!
Reading through slack, I'm wondering if I just need to install this module using:
Copy code
bundle: {
  nodeModules: ["@mailchimp/mailchimp_marketing"],
in my route definition? I tried that but got this error on build:
Copy code
Error: Cannot find a "package.json" in the function's srcPath: /Users/chris/Documents/xsol-app/src
Do I need to have a node_modules in my src folder? I currently have mailchimp installed in the root node_modules in the project root (where the .sst.json, etc. files are). Can it get pulled from there?
That’d be the first thing I’d try, prevents the bundler from doing anything with it
How do I get it to pull from the node_modules in the project root? SST is complaining there's not a package.json in my src/ directory. Thanks!
Strange, the node_modules folder should be at the root, same level as the sst.json
It is, and I do have the module installed there. It's in the root package.json:
Copy code
"dependencies": {
    "@mailchimp/mailchimp_marketing": "^3.0.74",
    "@serverless-stack/cli": "0.66.3",
    "@serverless-stack/resources": "0.66.3",
    "aws-cdk-lib": "2.7.0",
    "email-validator": "^2.0.4"
But when I build, SST says it's looking for a package.json in my src folder:
Copy code
Error: Cannot find a "package.json" in the function's srcPath: /Users/chris/Documents/xsol-app/src
I changed my function definition to remove the srcPath property and included the full path in the hander property and now it's working.
I've been grappling with this exact issue for longer than I'd like to admit and this helped! Thanks