Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build error with version 2.3.1: @parcel/core: Failed to resolve 'process' from ... #7697

Closed
spointecker opened this issue Feb 11, 2022 · 57 comments · Fixed by #7735
Closed

Comments

@spointecker
Copy link

🐛 bug report

I just upgraded to version 2.3.1 and now the build process fails.
Don't know exactly if this is a parcel or a sentry issue?

🎛 Configuration (.babelrc, package.json, cli command)

{
    "presets": [
        [
            "@babel/preset-env",
            {
                "modules": false,
                "useBuiltIns": false,
                "targets": {
                    "node": "current"
                }
            }
        ],
        "@babel/preset-react"
    ],
    "plugins": [],
    "env": {
        "test": {
            "plugins": ["@babel/plugin-transform-modules-commonjs"]
        }
    }
}

🤔 Expected Behavior

Build should pass.

😯 Current Behavior

The build fails with the following exception:

🚨 Build failed.

@parcel/core: Failed to resolve 'process' from './node_modules/@sentry/utils/esm/node.js'

  /Users/*****/Sites/*****/node_modules/@sentry/utils/esm/node.js:18:43
    17 | /**
  > 18 |  * Requires a module which is protected against bundler minification.
  >    |                                           ^^^^^^^^
    19 |  *
    20 |  * @param request The module path to resolve

💁 Possible Solution

idk.

🔦 Context

💻 Code Sample

🌍 Your Environment

Software Version(s)
Parcel 2.3.1
Node 16.11.1
npm/Yarn yarn: 1.22.17
Operating System mac osx
@klausbreyer
Copy link

klausbreyer commented Feb 11, 2022

Having the same issue.
For me it is with the contentful npm module.

rm -rf .parcel-cache && yarn start
yarn run v1.22.15
warning package.json: No license field
$ parcel public/index.html
Server running at http://localhost:1234
🚨 Build failed.

@parcel/core: Failed to resolve 'process' from
'./node_modules/contentful-sdk-core/dist/index.es-modules.js'

  /Users/kb1/versioned/yhb113-fillter.me-unified/web/node_modules/contentful-sdk-core/dist/index.es-modules.js:257:17
    256 |    **/
  > 257 | peof process !== 'undefined' && !process.browser;
  >     |      ^^^^^^^
    258 | }
    259 | function isReactNative() {

It started with 2.3.0.

.parcelrc

  "extends": "@parcel/config-default",
  "transformers": {
    "*.css": [
      "@parcel/transformer-css-experimental"
    ]
  },
  "optimizers": {
    "*.css": [
      "@parcel/optimizer-css"
    ]
  }
}

(Same behaviour with empty .parcelrc)

@koskokos2
Copy link

koskokos2 commented Feb 11, 2022

Have the same problem with axios.

Temporary workaround is to add alias to package.json :

"alias": {
    "process": false
 }

@mattlockyer
Copy link

I was having this issue related to js-sha256

#7060 (comment)

This solved it, in builds and dev. Basically, define process for the browser as an empty object:

"alias": {
		"process": {
			"global": "{}"
		}
	},
	```

@devongovett
Copy link
Member

I tried the following code:

import axios from 'axios';
console.log(axios)

and the console output was:

Building...

@parcel/resolver-default: Auto installing polyfill for Node builtin module "process"...

  /Users/devongovett/Downloads/test-92/node_modules/axios/lib/defaults.js:22:21
    21 |     adapter = require('./adapters/xhr');
  > 22 |   } else if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
  >    |                     ^^^^^^^ used here
    23 |     // For node use HTTP adapter
    24 |     adapter = require('./adapters/http');

  📝 Learn more: https://parceljs.org/features/node-emulation/#polyfilling-%26-excluding-builtin-node-modules

Installing process...
Bundling...
Packaging & Optimizing...
✨ Built in 1.48s

dist/test.js    19.37 KB    286ms

So, it auto installed process successfully and built. Is there another way to reproduce this?

@koskokos2
Copy link

koskokos2 commented Feb 11, 2022

@devongovett for me it is reproducible quite easily. The simplest example would be 2 file project:

index.html:

<script type="module">
  import axios from "axios";
</script>

package.json:

  "scripts": {
    "start": "parcel index.html"
  },
  "devDependencies": {
    "parcel": "2.3.1"
  },
  "dependencies": {
    "axios": "0.25.0"
  }

that results in the error noted by others above:

npm start

> @ start /Users/kos/test
> parcel index.html

Server running at http://localhost:1234
🚨 Build failed.

@parcel/core: Failed to resolve 'process' from './node_modules/axios/lib/defaults.js'

  /Users/kostiantyn.moroz/Documents/parcel/packages/examples/react-refresh/node_modules/axios/lib/defaults.js:22:21
    21 |     adapter = require('./adapters/xhr');
  > 22 |   } else if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
  >    |                     ^^^^^^^
    23 |     // For node use HTTP adapter
    24 |     adapter = require('./adapters/http');

Tried on both Node 14 and Node 16 with the same outcome.

I also tried enabling more logging by npm start -- --log-level verbose but as soon as it encounters any error it replaces any verbose output with just this error resulting in verbose logging appearing on the screen for a split second.

@chang-ryan
Copy link

just linking my issue repro here as well: #7060 (comment)

also a problem with js-sha3 like @mattlockyer

glad to help contribute to this fix as well

@devongovett
Copy link
Member

@koskokos2 if you run Parcel and pipe the output to cat you can see the full output.

parcel index.html | cat

@koskokos2
Copy link

Oh, thanks. Looks like it tried to auto-install process but didn't. With axios supporting both Node and browser it should not really care about polyfills for it. I would probably even prefer an option to disable this auto-install Node polyfills altogether. Here is my output anyway:

npm start -- --log-level verbose | cat

> start
> parcel index.html "--log-level" "verbose"

Server running at http://localhost:1234

@parcel/resolver-default: Auto installing polyfill for Node builtin module "process"...

  /Users/kos/test/node_modules/axios/lib/defaults.js:22:21
    21 |     adapter = require('./adapters/xhr');
  > 22 |   } else if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
  >    |                     ^^^^^^^ used here
    23 |     // For node use HTTP adapter
    24 |     adapter = require('./adapters/http');

  📝 Learn more: https://parceljs.org/features/node-emulation/#polyfilling-%26-excluding-builtin-node-modules

🚨 Build failed.

@parcel/core: Failed to resolve 'process' from './node_modules/axios/lib/defaults.js'

  /Users/kos/test/node_modules/axios/lib/defaults.js:22:21
    21 |     adapter = require('./adapters/xhr');
  > 22 |   } else if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
  >    |                     ^^^^^^^
    23 |     // For node use HTTP adapter
    24 |     adapter = require('./adapters/http');

@chang-ryan
Copy link

chang-ryan commented Feb 11, 2022

another weird thing i noticed using the alias workaround

build works when explicitly providing a source

this works
...
"scripts": {
  "serve": "parcel src/index.html",
  "build": "parcel build src/index.html"
},
...

but it doesn't work when you state a source as a field in the package.json

this does not work
...
"source": "src/index.html",
"scripts": {
  "serve": "parcel src/index.html",
  "build": "parcel build"
},
...

@CrommVardek
Copy link

@koskokos2 :

For me, I've added the following to my package.json :
"alias": { "process": false }

Now I can build on docker and it's working fine on nginx (ya!) but on local it does not work anymore... (Process is undefined)

I think I'm gonna downgrade to parcel 2.2 for now until it's resolved...

@spointecker spointecker changed the title Build error with version 2.3.1 and Sentry 6.16.7 Build error with version 2.3.1: @parcel/core: Failed to resolve 'process' from ... Feb 14, 2022
@henri-hulski
Copy link

Here I've the same problem with overmind and overmind-react.
They're just using process to check if it's a node environment.
So the "alias": { "process": false } hack worked here.

@niicojs
Copy link
Contributor

niicojs commented Feb 14, 2022

Same issue, also with Axios.
Parcel doesn't seeem to auto install process polyfill.

Update: I can see it briefly that it detects there is process to be installed but it quickly get back to the error.

@ilukin89
Copy link

Adding "alias": { "process": false } worked for me too. Thank you everyone, I had issues for days with axios error

@tpudel
Copy link

tpudel commented Feb 15, 2022

Having this error as well from migration from v1 to v2, even downgrading to 2.2 did not work, polyfill does not seem to be installing like the logs say.

"alias": { "process": "process/browser.js", "assert": "assert" } worked for me to get around this, but had to manually install both process and assert before the aliases were utilized.

Alias Reference: https://parceljs.org/features/node-emulation/

@nwhitmont
Copy link

nwhitmont commented Feb 16, 2022

I'm upgrading from 2.2.1 to 2.3.1, this time I'm getting same issue with NodeJS built-ins, for me it is Buffer.

@parcel/core: Failed to resolve 'buffer'

  • Node: LTS 16.14.0
  • Yarn: 1.22.15
  • OS: Windows (local dev), Linux (Bitbucket pipeline)

@ekeyser
Copy link

ekeyser commented Feb 17, 2022

For folks seeing issues with process and buffer, use @henri-hulski solution above and also node v17. Node v17 resolved issue with buffer for me.

@jbcz-tv
Copy link

jbcz-tv commented Feb 17, 2022

I was having this issue related to debug

@vladinator1000
Copy link

I get a similar error when trying to build Apollo Client, where ts-invariant fails to build with a @parcel/core: Failed to resolve 'process message.

Similarly to @tpudel I
yarn add proecess
then added this to package.json

"alias": { "process": "process/browser.js" }

@humphd
Copy link

humphd commented Feb 17, 2022

I'm hitting this when using aws-amplify:

parcel index.html | cat
Server running at http://localhost:1234
Building...

@parcel/resolver-default: Auto installing polyfill for Node builtin module
"process"...

  /private/tmp/fragments-ui/node_modules/@aws-amplify/core/src/JS.ts:178:10
    177 |   const isNode =
  > 178 |     typeof process !== 'undefined' &&
  >     |            ^^^^^^^^ used here
    179 |     process.versions != null &&
    180 |     process.versions.node != null;

  📝 Learn more:
     https://parceljs.org/features/node-emulation/#polyfilling-%26-excluding-builtin-node-modules

🚨 Build failed.

@parcel/core: Failed to resolve 'process' from
'./node_modules/@aws-amplify/core/lib-esm/JS.js'

  /private/tmp/fragments-ui/node_modules/@aws-amplify/core/lib-esm/JS.js:178:10
    177 |     }
  > 178 |     return ret;
  >     |          ^^^^^^^
    179 | };
    180 | /**

I tried to reduce it, but can't make it happen in isolation.

@rajsite
Copy link

rajsite commented Feb 18, 2022

Ran into a similar sounding error using 2.3.1:

@parcel/core: Failed to resolve 'buffer' from './src/main.ts'

I had to go to the Node Emulation: Polyfilling & Excluding Builtin Node Modules
table, find the package used for buffer, ie buffer, and manually install it. After that parcel was able to build successfully.

Similar to what tpudel described: #7697 (comment) but I did not need to create the alias for buffer, just install the npm package.

node v14.17.1 npm 7.24.2 parcel 2.3.1

devongovett added a commit that referenced this issue Feb 18, 2022

Verified

This commit was signed with the committer’s verified signature.
szokeasaurusrex Daniel Szoke
Fixes #7697
@MuhammadM1998
Copy link

MuhammadM1998 commented Feb 18, 2022

I'm having the same issue with firebase firestore

@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:5853:1
    5852 |         return t.store(e);
  > 5853 |     }
  >      | ^
    5854 |     // visible for testing
    5855 |     /** Parse User Agent to determine iOS version. Returns -1 if not found. */

Tried the mentioned solutions but nothing worked for me, here's what I did:

  • 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

Here's my package.json file snippet:

"scripts": {
        "dev": "parcel ./src/index.html --https --open firefox",
        "build": "npm run buildRelative && npm run updatePaths",
        "buildRelative": "parcel build --no-source-maps --public-url .",
        "updatePaths": "(Get-Content -Raw public/index.html) -replace 'src=\"', 'src=\"./' | Set-Content -NoNewLine public/index.html"
    },
    "devDependencies": {
        "autoprefixer": "^10.4.2",
        "parcel": "^2.3.1",
        "postcss": "^8.4.6",
        "tailwindcss": "^3.0.18"
    },
    "dependencies": {
        "firebase": "^9.6.6",
        "process": "^0.11.10",
        "vanilla-hamburger": "^0.2.3"
    },
    "alias": {
        "process": "false"
    }

@MuhammadM1998
Copy link

I'm having the same issue with firebase firestore

@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:5853:1
    5852 |         return t.store(e);
  > 5853 |     }
  >      | ^
    5854 |     // visible for testing
    5855 |     /** Parse User Agent to determine iOS version. Returns -1 if not found. */

Tried the mentioned solutions but nothing worked for me, here's what I did:

* 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

Here's my package.json file snippet:

"scripts": {
        "dev": "parcel ./src/index.html --https --open firefox",
        "build": "npm run buildRelative && npm run updatePaths",
        "buildRelative": "parcel build --no-source-maps --public-url .",
        "updatePaths": "(Get-Content -Raw public/index.html) -replace 'src=\"', 'src=\"./' | Set-Content -NoNewLine public/index.html"
    },
    "devDependencies": {
        "autoprefixer": "^10.4.2",
        "parcel": "^2.3.1",
        "postcss": "^8.4.6",
        "tailwindcss": "^3.0.18"
    },
    "dependencies": {
        "firebase": "^9.6.6",
        "process": "^0.11.10",
        "vanilla-hamburger": "^0.2.3"
    },
    "alias": {
        "process": "false"
    }

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

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

@jamiemcconnell
Copy link

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

Just changing process to the above as @MuhammadM1998 has without installing process as a dependancy works

@BraffZackland
Copy link

This issue is still present. The alias workaround worked to unblock me.

@Rigidity
Copy link

Rigidity commented Sep 11, 2022

Any updates on this? Having the same issue.

@guoyunhe
Copy link

guoyunhe commented Sep 17, 2022

Still have this error in parcel 2.7.0, with pnpm. Can you fix it?

@chenzx
Copy link

chenzx commented Sep 22, 2022

I've the similar problem. But i use my own globalThis.process=... runtime mock in my app code, so i think Parcel should NOT find polyfill when bundling with typeof process code...

@lzm0x219
Copy link

Any updates on this? Having the same issue.

@njleonzhang
Copy link

still having thi issue on node 14, parce 2.8 with pnpm, no issue with npm

@JonathonDunford
Copy link

JonathonDunford commented Nov 19, 2022

Bump, this is still an issue on 2.8.0
My issue specifically came about when trying to use bcrypt.
Parcel seems to try to polyfill a ton of dev dependencies including AWS SDK and process.

@wesbos
Copy link

wesbos commented Dec 20, 2022

Having is issue with parcel 2.8.2 and the axios library. Anyone know a fix?

@wesbos
Copy link

wesbos commented Dec 20, 2022

The fixes are conflicting now...

Sentry+Utils can be fixed with:

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

and axios can be fixed with

  "alias": {
    "process": false
  },

but how do I fix both?

@mischnic
Copy link
Member

@wesbos Can you share an example with the sentry and axios versions you're using? And what exactly are you importing from them?

@wesbos
Copy link

wesbos commented Dec 20, 2022

@mischnic Here is a very small reproduction:

https://github.com/wesbos/parcel-issues

@wesbos
Copy link

wesbos commented Dec 20, 2022

Thanks to @mischnic - found the issue. Apparently pnpm autoinstall is broken.

Add these dev deps to your package.json. Note I was using parcel in a workspace, but these need to be installed in the project root.

"buffer": "^5.5.0",
"process": "^0.11.10",

Then add these alias to package.json:

  "alias": {
    "process": "process/browser.js",
    "buffer": "buffer"
  },

Then install and run parcel, and you are back working!

also see node emulation

mikemoraned added a commit to mikemoraned/quarterly-clock that referenced this issue Dec 28, 2022
10:35:32 PM: @parcel/core: Failed to resolve 'process' from
10:35:32 PM: './node_modules/@sentry/utils/esm/node.js'` issue from parcel-bundler/parcel#7697 (comment)
jHwls added a commit to jHwls/workshop-semantics-html-aria that referenced this issue Feb 14, 2023
conao3 added a commit to conao3-playground/node-react-spectrum that referenced this issue Apr 9, 2023
Coow added a commit to RisingEmpires/aoe-4-countdown-timer that referenced this issue Oct 7, 2023
@damian-pastorini
Copy link

The "alias" solution doesn't work for me :( my issue is with "process" on a library I'm requiring.

@susanbakhtar
Copy link

hello, i did some process for run build. it works. but i didn't see any change in my project file . can i fix this?

Screenshot 1402-08-22 at 05 55 38

@skullface
Copy link

skullface commented Nov 28, 2023

I’ve just ran into this with NPM on a tiny project with no dependencies other than Parcel. I imagine my issue might be from not properly closing the port, as my terminal window was hanging so I force-quit it. Reloading my terminal didn’t fix the problem nor did a system restart. I use PNPM for other projects, so that may be the culprit? Wes’ workaround at #7697 (comment) solved the issue (server successfully started).

@jhobz
Copy link

jhobz commented Mar 16, 2024

I just ran into this issue on v2.11.0 in a GitHub action, but not when building locally. From the looks of things, it appears this was marked as fixed in v2.3.2, but yeah, just started getting the same issue in v2.11.0 after installing a new package (that presumably uses process).
image

Edit: to note, the workaround at #7697 (comment) does indeed work for me as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.