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

main.jsbundle does not exist. This must be a bug with React Native. metro/src/lib/polyfills/require.js: Unexpected token, expected "," #25397

Closed
kuzyakiev opened this issue Jun 25, 2019 · 8 comments
Labels
Bug Resolution: Locked This issue was locked by the bot. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used.

Comments

@kuzyakiev
Copy link

Archive in XCode lead to the error:
main.jsbundle does not exist. This must be a bug with React Native. metro/src/lib/polyfills/require.js: Unexpected token, expected ","

React Native version:

info 
  React Native Environment Info:
    System:
      OS: macOS 10.14.5
      CPU: x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
      Memory: 257.27 MB / 16.00 GB
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 10.14.1 - ~/.nvm/versions/node/v10.14.1/bin/node
      Yarn: 1.16.0 - ~/.yarn/bin/yarn
      npm: 6.4.1 - ~/.nvm/versions/node/v10.14.1/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
    IDEs:
      Android Studio: 3.3 AI-182.5107.16.33.5264788
      Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
    npmPackages:
      @storybook/react: ^5.0.11 => 5.0.11 
      @storybook/react-native: ^4.1.18 => 4.1.18 
      react: 16.8.3 => 16.8.3 
      react-native: 0.59.8 => 0.59.8 
    npmGlobalPackages:
      react-native-cli: 2.0.1

Steps To Reproduce

  1. XCode 10.2.1 (10E1001) > Product > Archive
  2. Got error:
+ BUNDLE_FILE=/Users/<mac-user-name>/Library/Developer/Xcode/DerivedData/********-dnnaonnrphjpphhhgmjunutlpwgi/Build/Intermediates.noindex/ArchiveIntermediates/********/BuildProductsPath/Release-iphoneos/********.app/main.jsbundle
+ node /opt/local/var/www/********/********-app/node_modules/react-native/cli.js bundle --entry-file index.js --platform ios --dev false --reset-cache --bundle-output /Users/<mac-user-name>/Library/Developer/Xcode/DerivedData/********-dnnaonnrphjpphhhgmjunutlpwgi/Build/Intermediates.noindex/ArchiveIntermediates/********/BuildProductsPath/Release-iphoneos/********.app/main.jsbundle --assets-dest /Users/<mac-user-name>/Library/Developer/Xcode/DerivedData/********-dnnaonnrphjpphhhgmjunutlpwgi/Build/Intermediates.noindex/ArchiveIntermediates/********/BuildProductsPath/Release-iphoneos/********.app
warning: the transform cache was reset.
Loading dependency graph, done.
error SyntaxError: /opt/local/var/www/********/********-app/node_modules/metro/src/lib/polyfills/require.js: Unexpected token, expected "," (341:5)

  339 |       _moduleObject.exports,
  340 |       dependencyMap
> 341 |     ); // avoid removing factory in DEV mode as it breaks HMR
      |      ^
  342 | 
  343 |     if (!__DEV__) {
  344 |       // $FlowFixMe: This is only sound because we never access `factory` again. Run CLI with --verbose flag for more details.
+ [[ false != true ]]
+ [[ ! -f /Users/<mac-user-name>/Library/Developer/Xcode/DerivedData/********-dnnaonnrphjpphhhgmjunutlpwgi/Build/Intermediates.noindex/ArchiveIntermediates/********/BuildProductsPath/Release-iphoneos/********.app/main.jsbundle ]]
+ echo 'error: File /Users/<mac-user-name>/Library/Developer/Xcode/DerivedData/********-dnnaonnrphjpphhhgmjunutlpwgi/Build/Intermediates.noindex/ArchiveIntermediates/********/BuildProductsPath/Release-iphoneos/********.app/main.jsbundle does not exist. This must be a bug with'
error: File /Users/<mac-user-name>/Library/Developer/Xcode/DerivedData/********-dnnaonnrphjpphhhgmjunutlpwgi/Build/Intermediates.noindex/ArchiveIntermediates/********/BuildProductsPath/Release-iphoneos/********.app/main.jsbundle does not exist. This must be a bug with
+ echo 'React Native, please report it here: https://github.com/facebook/react-native/issues'
React Native, please report it here: https://github.com/facebook/react-native/issues
+ exit 2

node_modules/metro/package.json

  "version": "0.51.1",
  "name": "metro",
  ...
  "repository": {
    "type": "git",
    "url": "git@github.com:facebook/metro.git"
  },

node_modules/metro/src/lib/polyfills/require.js

    if (hooks.length > 0) {
      for (var i = 0; i < hooks.length; ++i) {
        hooks[i].cb(moduleId, _moduleObject);
      }
    } // keep args in sync with with defineModuleCode in
    // metro/src/Resolver/index.js
    // and metro/src/ModuleGraph/worker.js

    factory(
      global,
      metroRequire,
      metroImportDefault,
      metroImportAll,
      _moduleObject,
      _moduleObject.exports,
      dependencyMap
    ); // avoid removing factory in DEV mode as it breaks HMR

    if (!__DEV__) {
      // $FlowFixMe: This is only sound because we never access `factory` again
      module.factory = undefined;
      module.dependencyMap = undefined;
    }

meanwhile react-native run-ios works without any errors.

Related issues: #15432

@kuzyakiev kuzyakiev added the Bug label Jun 25, 2019
@react-native-bot react-native-bot added the Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used. label Jun 25, 2019
@kuzyakiev
Copy link
Author

Fixed it with @nishiltamboli and @nadbm comments from #15432

I had a similar problem with node version. What I did was

Open console and type the command > which node
Copied the node path (in my case it came out to be /Users//.nvm/versions/node/v10.14.1/bin/node)
Open Xcode project
Open Project > Build Phases > Bundle React Native code and images
Change
export NODE_BINARY=node
../node_modules/react-native/scripts/react-native-xcode.sh

to

export NODE_BINARY=<PATH_FROM_WHICH_NODE>
../node_modules/react-native/scripts/react-native-xcode.sh

So for me, I changed it to

export NODE_BINARY=/Users//.nvm/versions/node/v10.14.1/bin/node
../node_modules/react-native/scripts/react-native-xcode.sh

Thats it! Hope it helps someone.

@ManigandanRaamanathan
Copy link

In my case, the metro bundler's project path that was running in background is not belonged to the project that I was trying to build.

@ScreamZ
Copy link

ScreamZ commented Feb 18, 2020

In my case, the metro bundler's project path that was running in background is not belonged to the project that I was trying to build.

That's the true issue, when switching project… Good catch

@2j2e
Copy link

2j2e commented Feb 25, 2020

Other case. I had the next line of code:

__DEV__ = false

(don't judge me) which doesn't break anything during the development, but breaks the build during release with original error message in the topic.
Any developer can have similar issue which breaks babel step, but you will find it as soon as you'll run bundle command

react-native bundle --minify --entry-file index.js --platform ios --dev false --bundle-output main.jsbundle

In my case the response was pretty clear:

TypeError: Property left of AssignmentExpression expected node to be of a type ["LVal"] but instead got "BooleanLiteral"```

@chanthientukk9
Copy link

chanthientukk9 commented Mar 5, 2020

@2j2e

react-native bundle --minify --entry-file index.js --platform ios --dev false --bundle-output main.jsbundle

I love you, you save my life. <3

@acro5piano
Copy link

acro5piano commented Mar 10, 2020

In my case, this error caused because of monorepo setup and React Native Cli project root.

react-native-xcode.sh refers $REACT_NATIVE_DIR/cli.js, and the script looks at monorepo root instead of React Native project root under the packages dir.

.
|-- package.json
|-- packages
|   `-- app
|       |- App.tsx                     # react native app
|       `- ios                         # native modules
|-- node_modules
|   `-- react-native
|       `- scripts
|          `- react-native-xcode.sh    # which will be invoked by Xcode
`-- cli.js                             # My custom cli

My Custom cli.js is looks like this to build the monorepo package. (ref: #25822 (comment))

process.chdir('./packages/app')

var cli = require('@react-native-community/cli')
cli.run()

Thus, I've changed Bundle React Native code and images in build phases so that react-native-xcode.sh invoke my custom react-native cli:

export NODE_BINARY=node
export CLI_PATH=./cli.js           // <-- Add this line
../../../node_modules/react-native/scripts/react-native-xcode.sh

Hope this helps someone like me.

@Jexim
Copy link

Jexim commented Jun 4, 2020

Don't forget close all metro bundler's (include current app develop bundler) before start build. It solved problem for me.

@manishkpr
Copy link

this article saved my day
https://bit.ly/3cQIIyX

@facebook facebook locked as resolved and limited conversation to collaborators Jun 25, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jun 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Resolution: Locked This issue was locked by the bot. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used.
Projects
None yet
Development

No branches or pull requests

9 participants