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

process undefined in react native environment #86

Closed
adrianofoschi opened this issue Mar 6, 2024 · 15 comments
Closed

process undefined in react native environment #86

adrianofoschi opened this issue Mar 6, 2024 · 15 comments

Comments

@adrianofoschi
Copy link

Hi, crypto-browserify uses this package and many react-native crypto apps use crypto-browserify.

Seems that the latest readable-stream downgrade in your package.json broken all this apps because process is not available.

In my case react native quick crypto.
Check this

margelo/react-native-quick-crypto#242 (comment)

Any workaround?

@ljharb
Copy link
Member

ljharb commented Mar 6, 2024

process is defined for any node module, so if metro isn't transpiling that by default then it's broken.

@ljharb
Copy link
Member

ljharb commented Mar 6, 2024

(A workaround is to declare a process global as an empty object, but it should really be fixed by default in metro)

@adrianofoschi
Copy link
Author

(A workaround is to declare a process global as an empty object, but it should really be fixed by default in metro)

Already tried it without success.

@ljharb
Copy link
Member

ljharb commented Mar 7, 2024

I'm empathatic to this breaking, to be clear. readable-stream v2 was never in v4 of this package, v3 was added in v4.1.0.

https://stackoverflow.com/a/42439338/632724 suggests that metro does handle this properly, altho that was back in 2017. The next answer, https://stackoverflow.com/questions/42437995/react-native-process-env-has-only-node-env, suggests using babel - which could transform process.browser into true. Would that work?

@adrianofoschi
Copy link
Author

adrianofoschi commented Mar 7, 2024

I'm empathatic to this breaking, to be clear. readable-stream v2 was never in v4 of this package, v3 was added in v4.1.0.

Yes it is what I meant. It works for me in v4.2.1 of this package. I see in your latest commit you downgrade readable-stream to v2 add added hash-base.

Commit 9e2bf12

https://stackoverflow.com/a/42439338/632724 suggests that metro does handle this properly, altho that was back in 2017. The next answer, https://stackoverflow.com/questions/42437995/react-native-process-env-has-only-node-env, suggests using babel - which could transform process.browser into true. Would that work?

I will try one of these solutions. Thanks.

@ValenberghsSven
Copy link

We are having the same issue in an Emberjs environment
"process is not defined"

Traced it back to the latest patch of this repo
v4.2.2...v4.2.3#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R40

Found the exact line that is throwing the error in readable-stream when comparing both versions
nodejs/readable-stream@v2.3.8...v3.6.2#diff-974ee391a6c413410bd53dd05ab5d0672c326587ba3a270c918168de594a75ddL146

We managed to fix it by adding process: 'process/browser.js', to our configuration

@ljharb
Copy link
Member

ljharb commented Mar 7, 2024

Without exception, your bundler is broken if this doesn't work by default, but I'm glad to hear that ember has a simple config to fix it.

@akshayOodlesTech
Copy link

Screenshot 2024-03-08 at 2 31 55 AM

Hi Team
Started getting this error since a few hours back.
Here is all I've tried so far -

  1. Installing process & including new webpack.ProvidePlugin({
    process: "process/browser"
    }) in webpack.config.js

  2. Declaring process as empty object in root js file of Project

but still no luck
Any support would be appreciated.
Thanks in Advance..

@ljharb
Copy link
Member

ljharb commented Mar 7, 2024

@akshayOodlesTech does your webpack config apply that plugin to node_modules code? if so, then i'd file an issue with webpack.

@rjblopes
Copy link

My comment on commit relates to this issue.

@printfn
Copy link

printfn commented Mar 20, 2024

I’m getting this issue with Vite. For now I’ve worked around it by adding this entry to the define section in my vite.config.ts:

export default defineConfig(env => ({
    define: {
        ...(process.env.VITEST ? {} : { 'process.version': JSON.stringify(process.version) }),
    },
}));

@ljharb
Copy link
Member

ljharb commented Mar 20, 2024

To be clear, that’s not a workaround, that’s the proper fix for vite.

@shamilovtim

This comment was marked as abuse.

@browserify browserify locked as off-topic and limited conversation to collaborators Apr 20, 2024
@ljharb

This comment was marked as off-topic.

@ljharb
Copy link
Member

ljharb commented Apr 21, 2024

Since using newer versions of readable-stream would be a breaking change, and the usage of process is inside readable-stream v3, it's not something that can (or should) be fixed here.

Solutions include 1) using a non-broken bundler, 2) configuring your broken bundler to ensure process is an object that always exists, or 3) get a readable-stream v3 backport patch published that doesn't assume the existence of process.

@ljharb ljharb closed this as not planned Won't fix, can't repro, duplicate, stale Apr 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants