Search code examples
node.jsreact-nativebuildyarnpkgnpm-scripts

Command 'yarn build' fails on Windows 10 for REACT_APP_RELEASE variable


Inside package.json the build script is something like:

"build": "REACT_APP_RELEASE=$npm_package_version REACT_APP_COMMIT_REF=$COMMIT_REF react-scripts build && echo $COMMIT_REF >> build/version.txt",

When I run the command yarn build I get following error:

'REACT_APP_RELEASE' is not recognized as an internal or external command, operable program or batch file. error Command failed with exit code 1.

What should I do?


Solution

  • Step 1

    Install the cross-env module.

    npm install cross-env
    

    or

    yarn add cross-env
    

    Step 2

    Add cross-env before REACT_APP_RELEASE variable in the build script. If REACT_APP_RELEASE variable is in the middle of your build script you have to always add cross-env just before the REACT_APP_RELEASE variable.

    Full command:

    "build": "cross-env REACT_APP_RELEASE=$npm_package_version REACT_APP_COMMIT_REF=$COMMIT_REF react-scripts build && echo $COMMIT_REF >> build/version.txt",