Skip to content

Build fails when package has no scripts #8291

Closed
@renato-bohler

Description

@renato-bohler

Describe the bug

When running react-scripts build the build fails if:

  • the project has no scripts on its package.json AND
  • the public pathname is set (via "homepage" on package.json or the PUBLIC_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.

const hasDeployScript = typeof appPackage.scripts.deploy !== 'undefined';

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

  1. Clone create-react-app
  2. Run yarn
  3. Run PUBLIC_URL=http://any.thing yarn build

OR

  1. Clone this repository
  2. Run yarn
  3. 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:

image

Reproducible demo

cra-build-issue, as mentioned on "Steps to reproduce", or create-react-app itself.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions