Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Firebase Functions fails to load because csv-parse/sync is missing

ErrorCannot 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.

  • Applies to Firebase CLI 13, Cloud Functions Node.js 22, csv-parse 5
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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-parse
  2. 2Match what you see, then jump to its fix

    1. 1grep 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. 2npm ls csv-parse works in the root but fails inside functionsThe package was installed in the project root, not in functionsFix
    3. 3ERR_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

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.json

2Fix

Install the package from inside the functions folder so it lands in that file's dependencies.

cd functions
npm install csv-parse

3Verify

Redeploy only the functions.

firebase deploy --only functions

Confirmed by firebase.google.com

Did this fix it?

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/null

2Fix

Move the dependency into the functions package.json.

npm uninstall csv-parse
cd functions && npm install csv-parse

3Verify

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

Did this fix it?

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/null

2Fix

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

Did this fix it?

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:

Related fixes

Back 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.