nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.59k stars 2.36k forks source link

nx:run-commands does not work in interactive CLIs like prisma #27305

Open CynicalBusiness opened 3 months ago

CynicalBusiness commented 3 months ago

Current Behavior

When trying to execute Prisma CLI commands, interactive input cannot be provided. Prisma presents the prompt to input, but nothing can be entered.

For example:

> nx run domain:migrate

> prisma migrate dev

Prisma schema loaded from prisma\schema.prisma
Datasource "db": PostgreSQL database <omitted>

? Enter a name for the new migration: »

I cannot, however, enter said migration name. No keyboard input (except Ctrl+C) works.

Expected Behavior

Entering interactive input is possible as it would be when ran directly (i.e. ./node_modules/.bin/prisma migrate dev or yarn prisma migrate dev)

GitHub Repo

No response

Steps to Reproduce

  1. Setup fresh Nx project (or use nx-examples)
  2. Install Prisma CLI with package manager of choice (i.e. yarn add -D prisma) and init (ex yarn prisma init)
  3. Setup target using nx:run-commands to execute, for example, prisma migrate dev
  4. Run the new target via nx, observe lack of interactivity.

Nx Report

Node           : 20.10.0
OS             : win32-x64
Native Target  : x86_64-windows
yarn           : 4.3.1

nx             : 19.5.5
@nx/js         : 19.5.5
@nx/jest       : 19.5.5
@nx/linter     : 19.5.5
@nx/eslint     : 19.5.5
@nx/workspace  : 19.5.5
@nx/devkit     : 19.5.5
@nx/nest       : 19.5.5
@nx/node       : 19.5.5
@nrwl/tao      : 19.5.5
@nx/web        : 19.5.5
@nx/webpack    : 19.5.5
typescript     : 5.5.4
---------------------------------------
Registered Plugins:
@nx/webpack/plugin
@nx/eslint/plugin
@nx/jest/plugin

Failure Logs

No response

Package Manager Version

No response

Operating System

Additional Information

I found and read through #8269, which sounds like my issue and was allegedly fixed in #21195, but it doesn't look like that was actually the case.

project.json:

{
  "name": "domain",
  ...
  "targets": {
    "migrate": {
      "executor": "nx:run-commands",
      "options": {
        "cwd": "packages/domain",
        "parallel": false,
        "forwardAllArgs": true,
        "command": "prisma migrate dev"
     }
  }
}

prisma/prisma.schema:

datasource db {
    provider = "postgresql"
    url      = env("DATABASE_URL")
}

generator client {
    provider = "prisma-client-js"
}

model Example {
   id Int @id @default(autoincrement())
}
FrozenPandaz commented 2 months ago

You can enable the new behavior with NX_NATIVE_COMMAND_RUNNER=true.

This is actually on by default on everywhere except for windows. There is an open issue on Windows which was why we turned it off, https://github.com/nrwl/nx/issues/22358 so also follow for updates there.

saltman424 commented 2 months ago

@FrozenPandaz While https://github.com/nrwl/nx/issues/22358 is still an issue, any reason not to implement this fix: https://github.com/nrwl/nx/issues/8269#issuecomment-1612676715? It seems to resolve the issue without needing NX_NATIVE_COMMAND_RUNNER=true