Skip to content

Command Line Parameters causing bad option: --plopfile=plopfile.ts #456

@awhitford

Description

@awhitford

Summary

I am trying to pass command-line options to my plop script, but it instead provides an error message:

/usr/local/Cellar/node/22.9.0_1/bin/node: bad option: --plopfile=plopfile.ts
 ELIFECYCLE  Command failed with exit code 9.

I am using a TypeScript plopfile, inspired by #423 and documented here.

How to Reproduce

Create a package.json

{
  "name": "plop-cmd-bug",
  "type": "module",
  "scripts": {
    "plop": "cross-env NODE_OPTIONS='--import tsx' plop --plopfile=plopfile.ts"
  },
  "dependencies": {
    "plop": "^4.0.1",
    "typescript": "^5.6.3"
  },
  "devDependencies": {
    "cross-env": "^7.0.3",
    "tsx": "^4.19.1"
  },
  "packageManager": "[email protected]+sha512.e5a7e52a4183a02d5931057f7a0dbff9d5e9ce3161e33fa68ae392125b79282a8a8a470a51dfc8a0ed86221442eb2fb57019b0990ed24fab519bf0e1bc5ccfc4"
}

Create a plopfile.ts

import type { NodePlopAPI } from "plop";

export default function (plop: NodePlopAPI) {
  plop.setGenerator("sample", {
    description: "Sample Generator to show bug with command line arguments.",
    prompts: [
      {
        type: "input",
        name: "name",
        message: "Project Name:",
      },
      {
        type: "input",
        name: "title",
        message: "Project Title:",
      },
    ],
    actions: ["No operation necessary"],
  });
}

Install dependencies

pnpm install

Validate that Prompts Work Fine

Run the plop script and answer the prompts. It will look something like this:

$ pnpm plop sample

> plop-cmd-bug@ plop /Users/anthony/github/awhitford/plop-cmd-bug
> cross-env NODE_OPTIONS='--import tsx' plop --plopfile=plopfile.ts "sample"

? Project Name: my-name
? Project Title: My Title
ℹ No operation necessary

Use Command Line Parameters to Bypass Prompts 🐛

Run the plop script with answers to bypass the prompts. It will look something like this:

$ pnpm plop sample -- --name my-name --title "My Title"

> plop-cmd-bug@ plop /Users/anthony/github/awhitford/plop-cmd-bug
> cross-env NODE_OPTIONS='--import tsx' plop --plopfile=plopfile.ts "sample" "--" "--name" "my-name" "--title" "My Title"

/usr/local/Cellar/node/22.9.0_1/bin/node: bad option: --plopfile=plopfile.ts
 ELIFECYCLE  Command failed with exit code 9.

Interesting Note 🤔

If you only supply name and not title, then it works fine:

$ pnpm plop sample -- --name my-name

> plop-cmd-bug@ plop /Users/anthony/github/awhitford/plop-cmd-bug
> cross-env NODE_OPTIONS='--import tsx' plop --plopfile=plopfile.ts "sample" "--" "--name" "my-name"

? Project Title: My Title
ℹ No operation necessary

Also, if you remove the title from the prompts and simply have the one name prompt left, then that will work fine too:

$ pnpm plop sample -- --name my-name

> plop-cmd-bug@ plop /Users/anthony/github/awhitford/plop-cmd-bug
> cross-env NODE_OPTIONS='--import tsx' plop --plopfile=plopfile.ts "sample" "--" "--name" "my-name"

ℹ No operation necessary

Please help 🛟

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions