Home > Enterprise >  @parcel/core: Failed to resolve 'process' from './node_modules/@firebase/firestore/di
@parcel/core: Failed to resolve 'process' from './node_modules/@firebase/firestore/di

Time:02-19

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"
    }

CodePudding user response:

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.

CodePudding user response:

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

  • Related