Firebase Functions fails to load because csv-parse/sync is missing
Cannot find module 'csv-parse/sync'Short answer
Firebase installs only what the functions package.json lists under dependencies, and it ignores your local node_modules at deploy. So csv-parse must be declared there, installed inside the functions folder, and used through its documented csv-parse/sync entry point.
Fix it fast
1Find out which cause you have
Check whether csv-parse is declared where Firebase reads dependencies: the package.json inside the functions folder.
cd functions grep -n "csv-parse" package.json npm ls csv-parse2Match what you see, then jump to its fix
- 1
grep prints nothing, or csv-parse sits only in devDependencies or in the repo root package.jsoncsv-parse is not in the functions package.jsonFix - 2
npm ls csv-parse works in the root but fails inside functionsThe package was installed in the project root, not in functionsFix - 3
ERR_PACKAGE_PATH_NOT_EXPORTED, or a deep path such as csv-parse/lib/sync in the importThe import path is not one the package exposesFix
- 1
What does the error look like?
Cannot find module 'csv-parse/sync'Cannot find module 'csv-parse'
Cause 1 of 3
csv-parse is not in the functions package.json
1Check
Cloud Functions installs from the dependencies object of the functions package.json. Your local node_modules is not uploaded.
grep -n "dependencies" -A12 functions/package.json2Fix
Install the package from inside the functions folder so it lands in that file's dependencies.
cd functions
npm install csv-parse3Verify
Redeploy only the functions.
firebase deploy --only functionsConfirmed by firebase.google.com
Cause 2 of 3
The package was installed in the project root, not in functions
1Check
Node.js looks for a package in the node_modules next to the requiring file, then in each parent folder. Firebase deploys the functions folder on its own, so a package that only the root has will be absent.
ls node_modules/csv-parse 2>/dev/null
ls functions/node_modules/csv-parse 2>/dev/null2Fix
Move the dependency into the functions package.json.
npm uninstall csv-parse
cd functions && npm install csv-parse3Verify
The functions folder now resolves it.
cd functions && node -e "import('csv-parse/sync').then(m => console.log(typeof m.parse))"Confirmed by nodejs.org
Cause 3 of 3
The import path is not one the package exposes
1Check
When a package defines exports, only the listed entry points can be imported. csv-parse documents csv-parse/sync as its synchronous entry.
grep -rn "csv-parse" src index.* 2>/dev/null2Fix
Import exactly the documented entry point.
import { parse } from 'csv-parse/sync';3Verify
Run the one-line check from the previous cause.
cd functions && node -e "import('csv-parse/sync').then(m => console.log(typeof m.parse))"Confirmed by nodejs.org
How do I stop it coming back?
- Install every runtime package from inside functions, never from the repo root.
- Keep a lock file in functions so deploys install the versions you tested.
- Import only documented entry points of a package.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.
Related fixes
Back end
Firebase Cloud Functions respond slowly, especially on the first call
Every function in the project is slow after deploy, even tiny ones
Most slow first calls are cold starts: the runtime starts from scratch, loads your code and runs global-scope work before it can answer.
3 causes, each with a fixBack end
firebase-admin warns that FIREBASE_CONFIG is missing
Warning, FIREBASE_CONFIG environment variable is missing. Initializing firebase-admin will fail
Cloud Functions for Firebase sets FIREBASE_CONFIG for you; a script run with plain node does not have it.
3 causes, each with a fixBack end
firebase deploy --only functions fails with a generic deploy error
HTTP 429
The generic message hides a specific one.
3 causes, each with a fixBack end
firebase deploy cannot load the .env file in the functions folder
FirebaseError: Failed to load environment variables from .env
The CLI reads .env files from the functions folder at deploy time and rejects ones it cannot use.
3 causes, each with a fixBack end
firebase deploy cannot load your functions: user code failed to load
Functions codebase could not be analyzed successfully. It may have a syntax or runtime error
The Firebase CLI loads your functions code on your machine before it deploys, to learn which functions exist.
4 causes, each with a fixBack end
firebase deploy rejects the Node.js version in a Cloud Functions package.json
`runtime` field is required but was not found in firebase.json or package.json.
The Firebase CLI builds the runtime name straight from engines.node in package.json, so the value must be a plain version such as 22, and a version that Google has decommissioned is refused.
5 causes, each with a fix