5

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"
    }
Muhammad Mahmoud
  • 621
  • 1
  • 5
  • 21

3 Answers3

3

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

Muhammad Mahmoud
  • 621
  • 1
  • 5
  • 21
1

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.

ErnestoC
  • 2,660
  • 1
  • 6
  • 19
  • I read the issue and done all the suggested solutions with no success. I used "alias": {"process": "false"} in the package.json file, manually installed process package, used parcel src/index.html command and removed the source in the package.json file and updated to node 16.14.0 (was 16.13.1) but nothing of them worked – Muhammad Mahmoud Feb 18 '22 at 14:21
  • 1
    I edited my answer since Parcel version `2.3.2` has been released to address this issue. – ErnestoC Feb 23 '22 at 18:08
0

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

echo 'nodeLinker: node-modules' >> /opt/build/repo/.yarnrc.yml 
Andrew G
  • 51
  • 2
  • the problem mentioned is solved in the then-next version of parcel, update the package if you havent. I'd also recommend using vite – Muhammad Mahmoud Jun 27 '22 at 03:36