node.jsreact-nativeubuntunpmwindows-subsystem-for-linux

npx react-native init fails with "SyntaxError: Unexpected token '?'"


I tried to create a React Native project using the following command:

npx react-native init myApp

but it fails with the following error:

/home/toufik/node_modules/@react-native-community/cli-doctor/build/commands/doctor.js:127
    description: description ?? healthcheck.description,
                              ^

 SyntaxError: Unexpected token '?'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/home/toufik/node_modules/@react-native-community/cli-doctor/build/index.js:19:38)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)

I installed NPM with the command sudo apt-get install npm and I think there shouldn't be any problem with this.

My environment:


Solution

  • From the 0.72 React Native setup instructions:

    Node

    Follow the installation instructions for your Linux distribution to install Node 16 or newer.

    I recommend using nvm to install node to get the latest versions, etc.