t3-oss / create-t3-turbo

Clean and simple starter repo using the T3 Stack along with Expo React Native
https://turbo.t3.gg
MIT License
4.27k stars 350 forks source link

bug: pnpm build is not rebuilding dist folder after being deleted #1053

Open dBianchii opened 1 month ago

dBianchii commented 1 month ago

Provide environment information

System: OS: Linux 5.15 Ubuntu 20.04.6 LTS (Focal Fossa) CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-11390H @ 3.40GHz Memory: 3.94 GB / 15.36 GB Container: Yes Shell: 5.8 - /usr/bin/zsh Binaries: Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node Yarn: 1.22.21 - ~/.local/share/pnpm/yarn npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm pnpm: 9.0.4 - ~/.local/share/pnpm/pnpm bun: 1.1.3 - ~/.bun/bin/bun

Describe the bug

After deleting the either compiled dist folder in either packages/db or packages/api, when you call pnpm build for that directory once again, it seems that turbo is caching the result and not outputing the dist folder once again.

Link to reproduction

I mean... this repo?

To reproduce

  1. pnpm i on a clean repo (after doing pnpm clean:workspaces)
  2. pnpm build -F api or pnpm build -F db.
  3. Delete the dist folder of either package
  4. pnpm build -F api
  5. You'll receive a >>> FULL TURBO message and you will be sad.

Additional information

https://www.loom.com/share/87c7ac25faa242c8888217927fd11c0d?sid=2487cce1-ae7a-414e-a30b-8dcb69845db0

juliusmarminge commented 1 month ago

I think You have to delete the tsbuildinfo

dBianchii commented 1 month ago

I think You have to delete the tsbuildinfo

Even after deleting it inside node_modules/.cache/tsbuildinfo.json, this won't work.

dBianchii commented 1 month ago

I only managed to make it build again and output the dist folder, after deleting both packages/api/node_modules/.cache/tsbuildinfo.json and after deleting the root node_modules/.cache folder.

noxify commented 3 weeks ago

Had the same behavior. Tried it with pnpm clean:workspaces + deleting the /.turbo directory. Sometimes it worked... sometimes not.

Workaround is currently to use an alternative compiler/bundler. But not sure if this works for all use cases.

Currently I use tsup, but pkgroll or something else should work, too.

  System:
    OS: macOS 14.5
    CPU: (8) x64 Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
    Memory: 18.86 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.1.0 - ~/.nvm/versions/node/v22.1.0/bin/node
    Yarn: 3.5.1 - /usr/local/bin/yarn
    npm: 10.7.0 - ~/.nvm/versions/node/v22.1.0/bin/npm
    pnpm: 9.2.0 - ~/Library/pnpm/pnpm

Turbo version is 2.0.3

noxify commented 3 weeks ago

@dBianchii i spent some time at stackoverflow and found the following: https://stackoverflow.com/questions/59055799/tsc-not-creating-the-dist-folder

Updated my build command to

    "build": "rimraf dist/ && rimraf node_modules/.cache/tsbuildinfo.json && tsc --noEmit false --outDir dist",

and it seems to work


Here the relevant tsconfigs

// /apps/backend/tsconfig.json

{
  "extends": "@acme/tsconfig/base.json",
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    },
    "tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
  },
  "include": ["."],
  "exclude": ["node_modules", "dist"]
}
// /tooling/typescript/base.json

{
  "$schema": "https://json.schemastore.org/tsconfig",
  "compilerOptions": {
    "esModuleInterop": true,
    "skipLibCheck": true,
    "target": "ES2022",
    "lib": ["ES2022"],
    "allowJs": true,
    "resolveJsonModule": true,
    "moduleDetection": "force",
    "isolatedModules": true,

    "incremental": true,
    "disableSourceOfProjectReferenceRedirect": true,

    "strict": true,
    "noUncheckedIndexedAccess": true,
    "checkJs": true,

    "module": "Preserve",
    "moduleResolution": "Bundler",
    "noEmit": true
  },
  "exclude": ["node_modules", "build", "dist", ".next", ".expo"]
}
noxify commented 1 week ago

Hi,

short update: I'm currently evaluating the usage of "tsx" in prod via

node --import tsx src/index.ts

The node command is called in the Dockerfile of my app. With this call I don't have to call tsc or tsup can export always the ts files ( and there are no dev/build scripts inside the packages - if not needed (e.g. to generate the locale files) )

Why? Maybe it was just a misconfiguration on my side, but with the compiled files it got some errors while running vitest. If I fixed these issues, then the build failed... it's annoying and to make it work, I decided to switch to another approach.

Should we do it? Yes, no, maybe.

There is a gh issue where they did a quick benchmark. https://github.com/TypeStrong/ts-node/issues/104#issuecomment-1941702624

I added "tsx" as dependency and everything seems to work as expected. Have to test it in our K8S environment to see if we will get some memory/performance issues.