React-native: Bundling for Android release fails when assigning to process.env.NODE_ENV

Created on 18 May 2016  路  7Comments  路  Source: facebook/react-native

Using 26.0-rc or as far back as 23.0, adding the following line to a project causes the Android release process to fail, but not debug:

process.env.NODE_ENV = 'development';

Running the following causes it to fail:

node node_modules/react-native/local-cli/cli.js bundle --platform android --dev false --reset-cache true --entry-file index.android.js --bundle-output /Users/<user>/Workspace/<projectDir>/android/app/build/intermediates/assets/release/index.android.bundle --assets-dest /Users/<user>/Workspace/<projectDir>/android/app/build/intermediates/res/merged/release

but the following will succeed (--dev true):

node node_modules/react-native/local-cli/cli.js bundle --platform android --dev true --reset-cache true --entry-file index.android.js --bundle-output /Users/<user>/Workspace/<projectDir>/android/app/build/intermediates/assets/release/index.android.bundle --assets-dest /Users/<user>/Workspace/<projectDir>/android/app/build/intermediates/res/merged/release
Locked

Most helpful comment

A slightly more readable version of OP:

Using 26.0-rc or as far back as 23.0, adding the following line to a project causes the Android release process to fail, but not debug:

process.env.NODE_ENV = 'development';

Steps to reproduce:

Create a fresh project with above line:

$ react-native init bla
$ cd bla
$ echo "process.env.NODE_ENV = 'development';" >> index.android.js

Run

$ node node_modules/react-native/local-cli/cli.js bundle \
  --platform android \
  --dev false \
  --reset-cache true \
  --entry-file index.android.js \
  --bundle-output /tmp/index.android.bundle

Running with --dev true though does not trigger the issue.

All 7 comments

Full output:

[6:26:22 PM] <START> Building Dependency Graph
[6:26:22 PM] <START> Crawling File System
[6:26:23 PM] <START> find dependencies
[6:26:25 PM] <END>   Crawling File System (3110ms)
[6:26:25 PM] <START> Building in-memory fs for JavaScript
[6:26:25 PM] <END>   Building in-memory fs for JavaScript (150ms)
[6:26:25 PM] <START> Building in-memory fs for Assets
[6:26:26 PM] <END>   Building in-memory fs for Assets (111ms)
[6:26:26 PM] <START> Building Haste Map
[6:26:26 PM] <START> Building (deprecated) Asset Map
[6:26:26 PM] <END>   Building (deprecated) Asset Map (41ms)
[6:26:26 PM] <END>   Building Haste Map (219ms)
[6:26:26 PM] <END>   Building Dependency Graph (3598ms)
/Users/andrewtoth/Workspace/releaseError/node_modules/babel-core/lib/transformation/file/index.js:614
      throw err;
      ^

TypeError: /Users/andrewtoth/Workspace/releaseError/index.android.js: Property left of AssignmentExpression expected node to be of a type ["LVal"] but instead got "StringLiteral"
    at Object.validate (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-types/lib/definitions/index.js:115:13)
    at Object.validate (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-types/lib/index.js:552:9)
    at NodePath._replaceWith (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-traverse/lib/path/replacement.js:214:7)
    at NodePath.replaceWith (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-traverse/lib/path/replacement.js:192:8)
    at PluginPass.MemberExpression (/Users/andrewtoth/Workspace/releaseError/node_modules/react-native/packager/react-packager/src/JSTransformer/worker/inline.js:85:14)
    at newFn (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-traverse/lib/visitors.js:310:19)
    at NodePath._call (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-traverse/lib/path/context.js:78:18)
    at NodePath.call (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-traverse/lib/path/context.js:49:17)
    at NodePath.visit (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-traverse/lib/path/context.js:108:12)
    at TraversalContext.visitQueue (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-traverse/lib/context.js:174:16)
/Users/andrewtoth/Workspace/releaseError/node_modules/babel-core/lib/transformation/file/index.js:614
      throw err;
      ^

TypeError: /Users/andrewtoth/Workspace/releaseError/index.android.js: Property left of AssignmentExpression expected node to be of a type ["LVal"] but instead got "StringLiteral"
    at Object.validate (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-types/lib/definitions/index.js:115:13)
    at Object.validate (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-types/lib/index.js:552:9)
    at NodePath._replaceWith (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-traverse/lib/path/replacement.js:214:7)
    at NodePath.replaceWith (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-traverse/lib/path/replacement.js:192:8)
    at PluginPass.MemberExpression (/Users/andrewtoth/Workspace/releaseError/node_modules/react-native/packager/react-packager/src/JSTransformer/worker/inline.js:85:14)
    at newFn (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-traverse/lib/visitors.js:310:19)
    at NodePath._call (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-traverse/lib/path/context.js:78:18)
    at NodePath.call (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-traverse/lib/path/context.js:49:17)
    at NodePath.visit (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-traverse/lib/path/context.js:108:12)
    at TraversalContext.visitQueue (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-traverse/lib/context.js:174:16)
/Users/andrewtoth/Workspace/releaseError/node_modules/babel-core/lib/transformation/file/index.js:614
      throw err;
      ^

TypeError: /Users/andrewtoth/Workspace/releaseError/index.android.js: Property left of AssignmentExpression expected node to be of a type ["LVal"] but instead got "StringLiteral"
    at Object.validate (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-types/lib/definitions/index.js:115:13)
    at Object.validate (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-types/lib/index.js:552:9)
    at NodePath._replaceWith (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-traverse/lib/path/replacement.js:214:7)
    at NodePath.replaceWith (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-traverse/lib/path/replacement.js:192:8)
    at PluginPass.MemberExpression (/Users/andrewtoth/Workspace/releaseError/node_modules/react-native/packager/react-packager/src/JSTransformer/worker/inline.js:85:14)
    at newFn (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-traverse/lib/visitors.js:310:19)
    at NodePath._call (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-traverse/lib/path/context.js:78:18)
    at NodePath.call (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-traverse/lib/path/context.js:49:17)
    at NodePath.visit (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-traverse/lib/path/context.js:108:12)
    at TraversalContext.visitQueue (/Users/andrewtoth/Workspace/releaseError/node_modules/babel-traverse/lib/context.js:174:16)
/Users/andrewtoth/Workspace/releaseError/node_modules/promise/lib/done.js:10
      throw err;
      ^

Error: Uncaught error in the transformer worker: /Users/andrewtoth/Workspace/releaseError/node_modules/react-native/packager/transformer.js
    at index.js:109:33
    at tryCallOne (/Users/andrewtoth/Workspace/releaseError/node_modules/promise/lib/core.js:37:12)
    at /Users/andrewtoth/Workspace/releaseError/node_modules/promise/lib/core.js:123:15
    at flush (/Users/andrewtoth/Workspace/releaseError/node_modules/asap/raw.js:50:29)
    at _combinedTickCallback (node.js:376:9)
    at process._tickCallback (node.js:407:11)

A slightly more readable version of OP:

Using 26.0-rc or as far back as 23.0, adding the following line to a project causes the Android release process to fail, but not debug:

process.env.NODE_ENV = 'development';

Steps to reproduce:

Create a fresh project with above line:

$ react-native init bla
$ cd bla
$ echo "process.env.NODE_ENV = 'development';" >> index.android.js

Run

$ node node_modules/react-native/local-cli/cli.js bundle \
  --platform android \
  --dev false \
  --reset-cache true \
  --entry-file index.android.js \
  --bundle-output /tmp/index.android.bundle

Running with --dev true though does not trigger the issue.

Fixed by using process.env["NODE_ENV"] instead of process.env.NODE_ENV.

How can I make NODE_ENV set to production on ios? I am using a scheme set to release and that is not working.

@andrewtoth react-native/node_modules/react-native/local-cli/bundle/buildBundle.js seems to use process.env.NODE_ENV. I changed it locally to use process.env["NODE_ENV"] and it still threw this error. The only way I could get this error to be removed was to comment out the line. Thoughts?

I don't think this issue should be closed since square bracket and dot notation are both valid, it should be bundling correctly in production.

@andrewtoth could you re-open this?

Object.assign(process.env, {"NODE_ENV": "development"}) seems to work.

Was this page helpful?
0 / 5 - 0 ratings