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

🐛 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

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 19
  • Comments: 57 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Have the same problem with axios.

Temporary workaround is to add alias to package.json :

"alias": {
    "process": false
 }

@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…

I was having this issue related to js-sha256

https://github.com/parcel-bundler/parcel/issues/7060#issuecomment-1035880313

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

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

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

Any updates on this? Having the same issue.

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)

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

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/

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

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)

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.

Using 2.7.0 I still had to apply the alias workaround.

v2.3.2 has a fix. Please let me know if it works for you.

@devongovett #7735 amazing, thank you for fixing!

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?

Ok, just for following up:

  • I had my env file in <project_root>/src/.env
  • Need to be in <project_root>/.env
  • I deleted the .parcel-cache directory, ran parcel build, then re-ran parcel serve (somehow needed to run build before…)
  • All good !

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

image

Using alias false doesn’t work:

{
    "license": "UNLICENSED",
    "alias": {
        "fs": false,
        "os": false,
        "path": false,
        "util": false,Ï
        "process": false
    },
}

Then it must come from my setup. Thanks for letting me know.

@eightyfive hey there - I’m running v14 node, just installed 2.3.2 parcel and I am loading a .env which appear to be loaded correctly. But I’m not sure if there’s something with my app/env that’s wildly different from yours - I’m sure there is just not sure what info you would need to help with that.

Did you try

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

?

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

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

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: https://github.com/parcel-bundler/parcel/issues/7697#issuecomment-1040867550 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

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

parcel index.html | cat