Build fails when package has no scripts
Created by: renato-bohler
Describe the bug
When running react-scripts build
the build fails if:
- the project has no
scripts
on itspackage.json
AND - the public pathname is set (via
"homepage"
onpackage.json
or thePUBLIC_URL
env variable) AND - the public pathname contains
.github.io/
This might happen if one is using yarn workspaces and all scripts of the React application are declared on the workspace root package.
It seems that the problem lies on printHostingInstructions.js
, as it tries to access deploy
of scripts
without checking if scripts
exists first.
Did you try recovering your dependencies?
Yes
Which terms did you search for in User Guide?
- build
- deploy
- PUBLIC_URL
- homepage
- scripts
Environment
npx: installed 91 in 5.921s
Environment Info:
System:
OS: Linux 5.3 Linux Mint 19.3 (Tricia)
CPU: (8) x64 Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
Binaries:
Node: 8.17.0 - /usr/bin/node
Yarn: 1.21.1 - ~/.yarn/bin/yarn
npm: 6.13.4 - /usr/bin/npm
Browsers:
Chrome: 79.0.3945.88
Firefox: 71.0
npmPackages:
react: ^16.12.0 => 16.12.0
react-dom: ^16.12.0 => 16.12.0
react-scripts: 3.3.0 => 3.3.0
npmGlobalPackages:
create-react-app: Not Found
Steps to reproduce
- Clone create-react-app
- Run
yarn
- Run
PUBLIC_URL=http://any.thing yarn build
OR
- Clone this repository
- Run
yarn
- Run
PUBLIC_URL=http://renato-bohler.github.io/my-app yarn build
Expected behavior
Build shouldn't fail.
Actual behavior
Build is failing with the message:
Cannot read property 'deploy' of undefined
Note that without setting PUBLIC_URL
, the problem doesn't occur:
Reproducible demo
cra-build-issue, as mentioned on "Steps to reproduce", or create-react-app itself.