Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dBianchii opened this issue May 28, 2024 · 9 comments
Closed

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

dBianchii opened this issue May 28, 2024 · 9 comments

Comments

@dBianchii
Copy link
Contributor

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
Copy link
Member

I think You have to delete the tsbuildinfo

@dBianchii
Copy link
Contributor Author

dBianchii commented May 28, 2024

I think You have to delete the tsbuildinfo

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

@dBianchii
Copy link
Contributor Author

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
Copy link
Contributor

noxify commented Jun 12, 2024

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
Copy link
Contributor

noxify commented Jun 12, 2024

@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
Copy link
Contributor

noxify commented Jun 26, 2024

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.
TypeStrong/ts-node#104 (comment)

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.

@juliusmarminge
Copy link
Member

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.

I don't think you have to delete the root one, just the one for the task you wanna bust the cache for. I don't know if typescript is able to restore the output or if it just uses the cache for incremental builds. Do you get a different behavior in a more minimal reproduction environment?

@dBianchii
Copy link
Contributor Author

dBianchii commented Jul 10, 2024

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.

I don't think you have to delete the root one, just the one for the task you wanna bust the cache for. I don't know if typescript is able to restore the output or if it just uses the cache for incremental builds. Do you get a different behavior in a more minimal reproduction environment?

I am using exactly stock and up to date create-t3-turbo. I just confirmed now that even after I delete only packages/api/node_modules/.cache folder and run pnpm build -F @acme/api, FULL TURBO will still appear and no dist folder appears.

@dBianchii
Copy link
Contributor Author

Fixed by #1140!! 🎉

Thank you @juliusmarminge

jaronheard added a commit to jaronheard/soonlist-turbo that referenced this issue Aug 23, 2024
jaronheard added a commit to jaronheard/soonlist-turbo that referenced this issue Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants