vercel / turborepo

Build system optimized for JavaScript and TypeScript, written in Rust
https://turbo.build/repo/docs
MIT License
26.21k stars 1.81k forks source link

[turborepo] Local scripts in workspaces don't work in npm scripts #4992

Closed vighnesh153 closed 1 year ago

vighnesh153 commented 1 year ago

What version of Turborepo are you using?

1.9.3

What package manager are you using / does the bug impact?

npm

What operating system are you using?

Mac

Describe the Bug

I have an app which has a local build script.

> root
    > apps
        > myApp
            package.json
            build.sh
    turbo.json
    package.json

In the npm scripts of the app, I have a npm build script which runs the local build script.

{
    "name": "sample-app",
    "version": "1.0.0",
    "private": true,
    "scripts": {
        "build": "./build.sh"
    }
}

When I run root's build script which runs turbo run build, my custom build shell script gets triggered. But when I run it in a CI environment or on Vercel, it is not able to find the shell script.

Here is a link to the failed Github Action run: https://github.com/vighnesh153/turbo-repo-build-check/actions/runs/4999749583/jobs/8956403830#step:5:15

Output when running locally

❯ npm run build

> build
> turbo run build

• Packages in scope: sample-app
• Running build in 1 packages
• Remote caching disabled
sample-app:build: cache miss, executing e58b841fe05c05d1
sample-app:build:
sample-app:build: > sample-app@1.0.0 build
sample-app:build: > ./build.sh
sample-app:build:
sample-app:build: Build script is running... ✅

 Tasks:    1 successful, 1 total
Cached:    0 cached, 1 total
  Time:    369ms

Output when running on a CI environment or Vercel

  npm run build
  shell: /usr/bin/bash -e {0}

> build
> turbo run build

• Packages in scope: sample-app
• Running build in 1 packages
• Remote caching disabled
sample-app:build: cache miss, executing e58b841fe05c05d1
sample-app:build: 
sample-app:build: > sample-app@1.0.0 build
sample-app:build: > ./build.sh
sample-app:build: 
sample-app:build: sh: 1: ./build.sh: not found
sample-app:build: npm ERR! Lifecycle script `build` failed with error: 
sample-app:build: npm ERR! Error: command failed 
sample-app:build: npm ERR!   in workspace: sample-app@1.0.0 
sample-app:build: npm ERR!   at location: /home/runner/work/turbo-repo-build-check/turbo-repo-build-check/apps/sample-app 
sample-app:build: ERROR: command finished with error: command (/home/runner/work/turbo-repo-build-check/turbo-repo-build-check/apps/sample-app) npm run build exited (1)

 Tasks:    0 successful, 1 total
Cached:    0 cached, 1 total
  Time:    599ms 
command (/home/runner/work/turbo-repo-build-check/turbo-repo-build-check/apps/sample-app) npm run build exited (1)

 ERROR  run failed: command  exited (1)
Error: Process completed with exit code 1.

Expected Behavior

Local script should be detected in packages.

To Reproduce

Reproduction Repo

https://github.com/vighnesh153/turbo-repo-build-check

NicholasLYang commented 1 year ago

Hey @vighnesh153, thanks for opening the issue. One thing I noticed is that your build.sh file is using zsh as the shell, while GitHub Actions is using bash. Could you try switching the shell in the build.sh to bash?

vighnesh153 commented 1 year ago

OMG!!!

That worked. I cannot believe this was the issue. All this time, I kept thinking that sh: 1: ./build.sh: not found meant that it is not able to locate the build.sh file.

Apologies for this and thanks for looking at this for me.

vighnesh153 commented 1 year ago

Just a follow up question, does Vercel also use bash because I got the same error when I tried to deploy my app on Vercel.

NicholasLYang commented 1 year ago

I believe so, but I'll double check!