Call a nested package.json script

1.4k Views Asked by At

So I have a package-scripts folder that holds all my scripts for building in the react environment:

const npsUtils = require('nps-utils')

module.exports = {
  scripts: {
    default: 'react-scripts start',
    build: 'react-scripts build',
    test: 'react-scripts test',
    eject: 'react-scripts eject',
    lint: {
      default: 'eslint ./ --ignore-path .gitignore',
      fix: 'yarn run lint -- --fix',
    },
    format: 'prettier --write "{,!(node_modules)/**/}*.js"',
    validate: npsUtils.concurrent.nps('lint', 'format', 'build'),
  },
}

However, when I try to call the lint fix script, it always fails. My call yarn start lint:fix always fails and gives the error

Scripts must resolve to strings. There is no script that can be resolved from "lint:fix"

So how do i call lint fix?

1

There are 1 best solutions below

0
On

You can do this:

scripts: {
  ...
  "lint:default": "eslint ./ --ignore-path .gitignore",
  "lint:fix": "yarn run lint -- --fix",
  ...
}

and call it by:

yarn start lint:fix