10

Today I updated to React Native Version 0.65.1. After that I was unable to Start the Metro Server

I am now receiving following error message while building a Release .apk:

    node_modules/metro/src/Server.js:350
  processRequest = (req, res, next) => {
                 ^

SyntaxError: Unexpected token =
    at new Script (vm.js:80:7)
    at createScript (vm.js:274:10)
    at Object.runInThisContext (vm.js:326:10)
    at Module._compile (internal/modules/cjs/loader.js:664:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
info Run CLI with --verbose flag for more details.

> Task :app:bundleReleaseJsAndAssets FAILED

I've tried:

  • Updating Node
  • Cleaning Project
  • Restarting Computer

This is the snippet from the Metro Server Node Module

processRequest = (req, res, next) => {
    this._processRequest(req, res, next).catch(next);
  };

Additional Information: I am using a MacBook Pro with macOS Big Sur 11.5.2

Thanks everyone

2
  • I am getting same issue, did you fixed the issue @Maaax ? Commented Oct 13, 2021 at 12:47
  • @Ravi Yes, mithunSalinda's Answer worked for me. It seems like it has something to do with node and nodes caching. After following the steps and updating Node again, I was even able to upgrade React Native again without any further problems. Commented Oct 14, 2021 at 13:24

6 Answers 6

22

Just my two cents: I had the same problem. My problem was due to NVM. I used node version 14 for the current project but my default version was node 10. And metro server opened in a new terminal that didn't use the current node but the default one. Fixed it by setting node version to 14.

Fix: nvm alias default v14.17.0

Sign up to request clarification or add additional context in comments.

2 Comments

not helped for me (
OMG! That is nifty.
1

I have a new React Native project on v0.66 and have encountered this but was able to fix it without downgrading.

So, I use nvm to manage my node versions and I'm on v16.13.0 currently, which should be ok, but it seems I also had node and yarn installed through brew. The node version in brew was v13.10.1.

To fix this:

  1. Uninstall node and yarn from brew

brew uninstall yarn

brew uninstall node

  1. Reinstall yarn globally through npm

npm install --global yarn

and it works 👍 hopefully this helps someone else

Comments

1

I am also using React Native latest version

"react": "17.0.2", "react-native": "0.66.2"

The problem in my system was the node version i was using node@10 and just using nvm i used default node version as node@14, which worked for me.

nvm use 14

Comments

0

I have used react native 0.66 after i downgraded into 0.64, this worked for me.

  1. downgrade react into 0.64.0
  2. clear node cache & gradle clean
  3. npm install

1 Comment

Downgrading is not an option when you are upgrading. How is this a serious answer?
0

For iOS only open xcode under "Build Phase" -> "Bundle React Native code and images" modify NODE_BINARY to absolute path of your nvm setting.

export NODE_BINARY=node
...

Find current absolute path of nvm node version using:

nvm use <your_version_here>
which node

Comments

0

I had the same problem with a new project with react 17 and react native 0.68, the fix for me was updating npm using this command:

npm install -g npm@latest

And updating nodejs from the official page (just downloading and installing the LTS version).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.