Installed netlify-cli, but missing all dependencies? (protobufjs among other)


Netlify site-name:
Issue: Netlify-cli 500 Internal Server error on invoke function

Hi! I tried following the getting started part of the Netlify-CLI docs, Get started with Netlify CLI | Netlify Docs.
I did the following steps:

  • npm install netlify-cli -g
  • netlify login
  • netlify functions:serve --functions [path-to-functions] --port [port-number]
  • From another terminal, netlify functions:invoke [name-of-function]

Invoking suddenly results in a cannot find module.
It works as intended on netlify servers.
It is just the CLI that is not working. Which makes my local dev feedback loop very long (have to push and deploy for every debug check).

Error: Cannot find module 'protobufjs'
Require stack:
- /Users/johannes/git/slackpic/.netlify/functions-serve/tokenRotation/node_modules/.pnpm/@grpc+proto-loader@0.7.10/node_modules/@grpc/proto-loader/build/src/index.js
- /Users/johannes/git/slackpic/.netlify/functions-serve/tokenRotation/node_modules/.pnpm/google-gax@4.3.0/node_modules/google-gax/build/src/grpc.js
- /Users/johannes/git/slackpic/.netlify/functions-serve/tokenRotation/node_modules/.pnpm/google-gax@4.3.0/node_modules/google-gax/build/src/index.js
- /Users/johannes/git/slackpic/.netlify/functions-serve/tokenRotation/node_modules/.pnpm/@google-cloud+firestore@7.3.0/node_modules/@google-cloud/firestore/build/src/index.js
- /Users/johannes/git/slackpic/.netlify/functions-serve/tokenRotation/node_modules/.pnpm/firebase-admin@12.0.0/node_modules/firebase-admin/lib/firestore/index.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
    at Function.Module._load (node:internal/modules/cjs/loader:985:27)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (/Users/johannes/git/slackpic/.netlify/functions-serve/tokenRotation/node_modules/.pnpm/@grpc+proto-loader@0.7.10/node_modules/@grpc/proto-loader/build/src/index.js:22:18)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19)

Response with status 500 in 1077 ms.

I kind of expected all dependencies to be added on npm install -g netlify-cli… Did I do something wrong?

Are you sure this is a Netlify CLI issue? It looks like you’re missing dependencies for your code and not Netlify CLI. Since you’re using pnpm, try using: .npmrc | pnpm

Shamefully hoist in .npmrc did indeed solve it, thank you!

I was certain it was a Netlify CLI issue, since it worked on Netlify servers and if I moved the function over to a regular Next.js endpoint, it worked as well. It was only when invoked through Netlify CLI that I got that error. But your tip with shamefully-hoist seem to have resolved my issues, and I can now test my functions locally instead of live :smiley: