@parcel/core: Failed to resolve 'process' from './node_modules/@firebase/firestore/dist/index.esm2017.js'

Viewed 1068

I'm working on a project and when I try to run parcel dev or build command it outputs the following error:

    × Build failed.
    @parcel/core: Failed to resolve 'process' from './node_modules/@firebase/firestore/dist/index.esm2017.js'
    
      D:\Workspace\Front-End\Apps\RISC-Aswan\node_modules\@firebase\firestore\dist\index.esm2017.js:5741:38
        5740 |         return t.store(e);
      > 5741 |     }
      >      |      ^
        5742 |     // visible for testing
        5743 |     /** Parse User Agent to determine iOS version. Returns -1 if not found. */

It was working before and now I don't know the cause of the problem. I tried to delete node__modules folder and run npm install but nothing changes.

I have the following imports in the script file:

import { initializeApp } from 'firebase/app';
import { getFirestore, collection, addDoc } from 'firebase/firestore';

the second line importing the firestore is what causing the problem, commenting it leads to everthing works fine.

Here's a photo with the terminal message and the esm2017.js file Error Message

My package.json dependecies:

    "devDependencies": {
        "autoprefixer": "^10.4.2",
        "parcel": "^2.2.1",
        "postcss": "^8.4.6",
        "tailwindcss": "^3.0.18"
    },
    "dependencies": {
        "firebase": "^9.6.6",
        "vanilla-hamburger": "^0.2.3"
    }
3 Answers

for some reason modifying alias to the following worked in dev and build

"alias": {
    "process": {
        "global": "{}"
    }
}

Here's the other suggested workaround i tried mentioned in this issue

  • used alias in my package.json file
     "alias": {
            "process": "false"
        }
  • manually installed process package
    "dependencies": {
        "process": "^0.11.10",
    },
  • updated node to v16.14.0 instead of v16.13.1.

  • used parcel build ./src/index.html and removed "source": "./src/index.html" in the package.json

In your package.json you are defining parcel to be the higher version compatible with 2.2.1:

    "devDependencies": {
        "autoprefixer": "^10.4.2",
        "parcel": "^2.2.1"
     // Rest of packages

Currently there is an issue in the GitHub repository for parcel regarding this problem with Firebase. While that issue shows your exact error message, the general issue to keep track of is this open issue, since this problem affects libraries other than Firebase. Something you could do is to avoid using an affected version of parcel (2.3.1 as far as I see on the issues), or keep track of the issue to update to a fixed version when it releases.

EDIT (2/23/2021):

It seems that both GitHub issues are now closed with the release of Parcel 2.3.2. I tested building a React project with Parcel and Firebase using version 2.3.1, and I encountered the exact same error as you. Updating to 2.3.2 solved the issue completely on my end without any other change of dependencies. Just in case anyone comes across this thread later on.

I was using yarn on netlify and had to do this to fix:

echo 'nodeLinker: node-modules' >> /opt/build/repo/.yarnrc.yml 
Related