Missing dependencies on pages that need a Netlify function

We’re migrating from Gatsby → Next.js and hitting some trouble with the build process. On the frontend we use a react pacakage that embeds twitter things. This works fine in local dev, and worked fine with our previous Gatsby site. However, I’m running into what seems like the stage that builds a function for a page that will need one is failing due to dependencies of some sort.

4:57:48 PM: ────────────────────────────────────────────────────────────────
4:57:48 PM:   Dependencies installation error                               
4:57:48 PM: ────────────────────────────────────────────────────────────────
4:57:48 PM: ​
4:57:48 PM:   Error message
4:57:48 PM:   A Netlify Function failed to require one of its dependencies.
4:57:48 PM:   Please make sure it is present in the site's top-level "package.json".
​
4:57:48 PM:   In file "/opt/build/repo/packages/site/netlify/functions/next_index/next_index.js"
4:57:48 PM:   Cannot find module 'enzyme'

I can install that, then it works, but then another is needed (react-native oddly enough) but then, I made them top-level dependencies to see if it would help, but then I get errors that the deployed size is too big.

5:07:35 PM: 9 new functions to upload
5:08:12 PM: Request must be smaller than 69905067 bytes for the CreateFunction operation
... continues on a while like this

Seems like I’m missing something about how dependency management works in the case of Next.js

Some meta info:

resistbot-website-ed6e4f
https://app.netlify.com/sites/resistbot-website-ed6e4f/deploys/60ba9fd839d4de0009150a97
https://app.netlify.com/sites/resistbot-website-ed6e4f/deploys/60baa2160609400008f21328

Some relevant config bits (using the plugin manually installed via NPM at the moment, will switch to the built-in variant once this code is being deployed on our main branch (co-existing with Gatsby right now):

[build]
  command = "yarn build"
  publish = ".next"
  environment = { NETLIFY_USE_YARN = "true", NEXT_IMAGE_ALLOWED_DOMAINS = "cdn.sanity.io", ACTIVE_ENV="staging" }

[context.production]
  environment = { ACTIVE_ENV = "production" }

[[plugins]]
  package = "@netlify/plugin-nextjs"

I’ve avoided using NODE_ENV=production as I haven’t yet figured out the “correct” structure for a package.json when the dev dependencies aren’t included. Since many “dev” deps are needed to build a prod site I haven’t figured out what should be included where. Perhaps there’s something to work on there as well.

Ok this is a surprising outcome:

which I found from: Request must be smaller than 69905067 bytes for the CreateFunction

❯ yarn why react-native-get-random-values
yarn why v1.22.10
[1/4] 🤔  Why do we have the module "react-native-get-random-values"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "react-native-get-random-values@1.7.0"
info Reasons this module exists
   - "_project_#@resistbot#site#@netlify#plugin-nextjs#@sls-next#lambda-at-edge#@aws-sdk#client-s3#@aws-sdk#middleware-retry" depends on it
   - Hoisted from "_project_#@resistbot#site#@netlify#plugin-nextjs#@sls-next#lambda-at-edge#@aws-sdk#client-s3#@aws-sdk#middleware-retry#react-native-get-random-values"
info Disk size without dependencies: "104KB"
info Disk size with unique dependencies: "120KB"
info Disk size with transitive dependencies: "120KB"
info Number of shared dependencies: 1
✨  Done in 1.06s.

Super unfortunate that this dependency is likely out of reach for you too. But perhaps you can nudge the AWS folks to reconsider this dependency, I’m a bit surprised how widespread it’s chaos is.

I just removed these (the netlify plugins) from my own package.json and the problem still exists (but at least I don’t have react-native-get-random-values in dependencies anymore). Failing now on react-native:

❯ yarn why react-native
yarn why v1.22.10
[1/4] 🤔  Why do we have the module "react-native"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
error We couldn't find a match!
✨  Done in 0.94s.
4:10:43 PM:   Error message
4:10:43 PM:   A Netlify Function failed to require one of its dependencies.
4:10:43 PM:   Please make sure it is present in the site's top-level "package.json".
​
4:10:43 PM:   In file "/opt/build/repo/packages/site/netlify/functions/next_index/next_index.js"
4:10:43 PM:   Cannot find module 'react-native'

Is it related somehow to target: 'experimental-serverless-trace' somehow?

Hi there, @embarrassment-setup :wave:

Thanks for your patience here and for your very detailed posts. We have not forgotten about this thread! I have looped in one of our teams to dig into your questions further. In the interim, please do let us know if you have taken any additional troubleshooting steps.

Thanks!
Hillary

Thanks, I’ve essentially removed/replaced anything that had these dependencies. I think I’d consider this issue closed, but there’s some oddities I’ve never seen before that (I think) might be a bit correlated with the netlify/next environments.

1 Like