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

Packager error: "Can't find variable: process" #73

Closed
richardgirges opened this issue Oct 10, 2017 · 35 comments
Closed

Packager error: "Can't find variable: process" #73

richardgirges opened this issue Oct 10, 2017 · 35 comments

Comments

@richardgirges
Copy link
Contributor

richardgirges commented Oct 10, 2017

Do you want to request a feature or report a bug?
Bug

Behavior
The issue was initially discovered in #65 after people began using the latest metro-bundler 0.20.0 version to work around dynamic requires in packages like moment.js

Packager throws the following error when bundling:

Unhandled JS Exception: Can't find variable: process

Repro Steps

  1. Add metro-bundler 0.20.0 to package.json as a "resolutions" entry for react-native:
"resolutions": {
  "react-native/metro-bundler": "0.20.0"
}
  1. Run react-native run-ios as normal.

NOTE: The fact that this issue manifested for people in metro-bundler@0.20.0 is a red herring. This issue appears to be happening with older versions of metro-bundler as well. I've confirmed the same error appears in metro-bundler@0.19.0. I haven't tried to reproduce it in any versions older than 0.19.0 yet.

Environment
Node: v8.5.0

package.json

  "dependencies": {
    "react": "16.0.0-beta.5",
    "react-native": "0.49.3"
  },
  "resolutions": {
    "react-native/metro-bundler": "0.19.0"  
  },
@tqc
Copy link

tqc commented Oct 10, 2017

I ran into that one last week. It seems to be related to the order things get packaged in - react native polyfills process.env, but does it after react tries to check if it is running in dev mode.

Putting the first RN import before the first react import seems to have fixed it, but it was working fine the other way around on previous versions.

@cpojer
Copy link
Contributor

cpojer commented Oct 10, 2017

Would be good to figure out which module is throwing this.

@tqc
Copy link

tqc commented Oct 10, 2017

In my case it was react - unlike #65 it’s not just a bundler setting/ error message. Were previous releases perhaps effectively hardcoded to load react native before anything else?

@mackenziemance
Copy link

mackenziemance commented Oct 10, 2017

@richardgirges Any updates on this ?

@brunocascio
Copy link

Please, take a look at this issue.

@fungilation
Copy link

Since moment is reverting their fix, a fix in Bundler would be appreciated!

@zuoge85
Copy link

zuoge85 commented Oct 12, 2017

+1

@tsyeyuanfeng
Copy link

process is set up in InitializeCore module of react-native.

// InitializeCore.js
// Set up process
global.process = global.process || {};
global.process.env = global.process.env || {};
if (!global.process.env.NODE_ENV) {
  global.process.env.NODE_ENV = __DEV__ ? 'development' : 'production';
}

So InitializeCore module must run before entry module. Previously, runBeforeMainModule config was specified in defaults.js where InitializeCore is included. But it has been removed from metro-bundler in this commit Make the runBeforeMainModule config param to RN repo and make it absolute recently. However, it seems that there are some problems with this commit, I've created another issue #78 to disscus about this.

@tqc
Copy link

tqc commented Oct 17, 2017

@tsyeyuanfeng That would explain why things suddenly stopped working.

See also the corresponding RN commit facebook/react-native@34487c0

Looks like that commit isn’t part of 0.49, but is tagged as v0.50.0-rc0 - it will work just fine with facebook’s internal setup (master of both in a single repo) but the open source dependencies are broken at the moment.

@amardeepranu
Copy link

Getting this error when trying to run on a device on RN v0.50.2

@blackxored
Copy link

Can confirm that 0.50.2 has this error. It only happens on release build for me though.

@JumalDB
Copy link

JumalDB commented Nov 8, 2017

I have this issue too on 0.50.2. Is there any workarounds?

@rafeca
Copy link
Contributor

rafeca commented Nov 8, 2017

We have just released metro-bundler v0.20.2, which should solve this issue. Can somebody confirm?

@JumalDB
Copy link

JumalDB commented Nov 8, 2017

It seems to fix Debug build (which can be run on ios devices now), however there is another Release build issue now:
facebook/react-native#16745

@PvanHengel
Copy link

We are seeing the same release build issue in ios, we didn't have any issues with the debug build. The Unhandled JS Exception: undefined is not an object (evaluating 'e.length')', reason: 'Unhandled JS Exception: undefined is not an object (evaluating 'e.length') is a major blocker, do we need to open another issue for that here, or should we keep this one open?

@bnjm
Copy link

bnjm commented Nov 8, 2017

@PvanHengel updating to RN 0.50.3 fixed this for me... hopefully fixes for you too.

@SSTPIERRE2
Copy link

SSTPIERRE2 commented Nov 8, 2017

Upgrading to RN 0.50.3 fixed this same issue for me too with a new project created this week! I hope upgrading fixes this for you all as well, and if you haven't done it before here's the doc: https://facebook.github.io/react-native/docs/upgrading.html cheers!

@JumalDB
Copy link

JumalDB commented Nov 9, 2017

RN 0.50.3 does not fix that another issue:
Unhandled JS Exception: undefined is not an object (evaluating 'e.length')

@PvanHengel
Copy link

@JuliusMalisauskasDB see facebook/react-native#16745 it is related to an issue which has been merged with the color-convert library. I believe the fix was merged.

@rmevans9
Copy link

@JuliusMalisauskasDB I resolved this issue with a yarn resolution to set color-convert to 1.9.1. There are a few libraries that seem to depend specifically on 1.9.0. For me it was react-native-svg

@DiederikvandenB
Copy link

I'm on 0.50.3 and I am still experiencing this issue.

@flylxq
Copy link

flylxq commented Nov 28, 2017

On 0.50.4 I am having this issue.
b27493c0-ccaa-4671-ae19-a770232e1233

@rafeca
Copy link
Contributor

rafeca commented Nov 28, 2017

Can you check which version of metro-bundler are you using? To do so, check for the metro-bundler entry on your yarn.lock file.

This issue was fixed in v0.20.2

@nsipplswezey
Copy link

Ran into the same error with a fresh clone+build of a previously functional project.

    "dependencies": {
        "react": "16.0.0",
        "react-native": "0.50.4"
    },

Did an rm yarn.lock and rm package-lock.json and an npm i.
Now my package-lock.json is:

        "metro-bundler": {                                                      
            "version": "0.20.3",
            "resolved": "https://registry.npmjs.org/metro-bundler/-/metro-bundler-0.20.3.tgz",

Though my node_modules/react-native/package.json shows

    "metro-bundler": "^0.20.1",  

Regardless I'm back up and running.
For anyone else stuck on this, my issue seemed to be an old yarn.lock file from maybe from an old yarn install, when currently I'm using npm install.

@rafeca
Copy link
Contributor

rafeca commented Dec 4, 2017

Thanks @nsipplswezey for shedding some light. In fact, package manager lock files will prevent updating to the metro version that fixed this issue (v0.20.3).

For anyone stumbling across this issue, remove the metro entry in your package-lock.json/yarn.lock file and npm install/yarn install again

@rafeca rafeca closed this as completed Dec 4, 2017
@glarivie
Copy link

glarivie commented Dec 4, 2017

On RN0.50.4, with metro-bundle@0.20.3 I am having this issue.

@rafeca
Copy link
Contributor

rafeca commented Dec 5, 2017

@hqro are you sure that the metro version that you're using is 0.20.3? Can you post the whole error stack trace you're getting?

@leavesster
Copy link

run react-native upgrade and close proxy(I don't think the proxy is the problem , but these are two things I done, after I have this issue) fix this problem.

My version:

react-native -v
react-native-cli: 2.0.1
react-native: 0.50.1

@glarivie
Copy link

glarivie commented Dec 6, 2017

@rafeca this is my yarn.lock

metro-bundler@^0.20.1, metro-bundler@^0.20.3:
  version "0.20.3"
  resolved "https://registry.yarnpkg.com/metro-bundler/-/metro-bundler-0.20.3.tgz#0ded01b64e8963117017b106f75b83cfc34f3656"

@albertobram
Copy link

I am running into this issue as well, I have these versions of the components:
metro-bundler 0.20.3
react 16.0.0
react-native 0.50.3

@janicduplessis
Copy link
Contributor

@rafeca Just hit this issue with metro@0.23.0. It only happens when generating a prod bundle. Looking at the bundle a module that uses process.env (in my case invariant) appears before the InitializeCore module. This causes it to be executed before process.env polyfill is setup. As a workaround I added import 'InitializeCore'; at the top of my index.js and now it works.

@rafeca
Copy link
Contributor

rafeca commented Dec 13, 2017

Hey @janicduplessis! Are you trying it with RN master?

I cannot repro it in my silly sample RN app: https://github.com/rafeca/rn-test-app if you have some repro steps I can take a deeper look

@rafeca
Copy link
Contributor

rafeca commented Dec 13, 2017

Ok, I've just actually been able to reproduce it, a fix is coming

@leai-jiang
Copy link

Also have this issue on react-native 0.52

@fungilation
Copy link

Works for me on 0.52.

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