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

ReferenceError: process is not defined #48

Open
Jack-Works opened this issue Jul 2, 2024 · 5 comments
Open

ReferenceError: process is not defined #48

Jack-Works opened this issue Jul 2, 2024 · 5 comments

Comments

@Jack-Works
Copy link
Contributor

ReferenceError: process is not defined
  at Readable.pipe (_stream_readable.js:581:1)
  at pipe (index.js:56:1)
  at Array.reduce (<anonymous>)
  at Object.pump [as default] (index.js:79:1)
  at new BaseProvider (BaseProvider.js:49:1)
  at new MetaMaskInpageProvider (MetaMaskInpageProvider.js:24:1)
  at createMetaMaskProvider (index.js:13:1)
@legobeat
Copy link
Contributor

legobeat commented Jul 2, 2024

@Jack-Works Which version is this? Are you getting this error also on the latest master?

@Jack-Works
Copy link
Contributor Author

Yes. This package relies on extension-port-stream and it relies on readable-stream. Three accesses to process (process.stdin, process.stdout and process.nextTick) happen in readable-stream. Is it possible to get rid of those dependencies?

@legobeat
Copy link
Contributor

legobeat commented Jul 3, 2024

Hmm, are you using any bundler? Currently, both readable-stream and metamask-extension-provider expect something like browserify or webpack to be used and polyfillys to be provided by the user.

process should get pulled inreadable-stream as transitive dependency already:

"process": "^0.11.10",

A quick fix I have not tried could be something like global.process = require('process') in your code, though that's not something we want to do in this package, I think.

Is it possible to get rid of those dependencies?

Probably, though it's not clear to me what the best way to achieve that is considering it comes from inside readable-stream.

@Jack-Works
Copy link
Contributor Author

webpack 5 (released in 2020) no longer provides polyfill for process (see https://webpack.js.org/migrate/5/#run-a-single-build-and-follow-advice)

I currently replaces process.stdin (and stdout) to null, and process.nextTick to a polyfill, but I want to avoid this, since this package is only used in browser, so there is no meaning to use a Node.js global.

@c1im4cu5
Copy link

c1im4cu5 commented Jul 5, 2024

I came upon the issue yesterday. Compiling webpack was successful. Upon utilzation of my extension, the above error began to appear.

The issue is occuring because process isn't native to the browser. My work-around to the problem was to perform the following steps:

Import and save process to environment:
npm install process --save

Modify your webpack configuration to include the 'process' polyfill:
plugins: [ new webpack.ProvidePlugin({ process: 'process/browser', }), ], resolve: { fallback: { "process": require.resolve("process/browser"), }, },

Import to designated file (this can be done be following the error to the source file; which is likely in the node_modules directory):
import process from 'process';

I hope this helps!

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

No branches or pull requests

3 participants