Race condition causing errors chmod'ing DTS files with shebangs
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 275
- PR merge metrics
- No merged PRs in 30d
Description
I'm seeing build errors related to .ts files that contain `#!/usr/bin/env node`, which tsup tries to **chmod +x** in order to ensure they are executable:
```
⋮
ESM dist/integrations/webpack-plugin.mjs 2.93 KB
ESM dist/imperativeAPI/useIntl.mjs 428.00 B
ESM dist/compiledLocales/es.mjs 4.58 KB
ESM dist/compiledLocales/sr.mjs 7.41 KB
ESM dist/types/index.mjs 156.00 B
ESM dist/compiledLocales/et.mjs 4.54 KB
ESM ⚡️ Build success in 140ms
DTS Build start
Error: ENOENT: no such file or directory, chmod '/Users/kyank/Developer/unified-home/packages/i18n-react-intl/dist/scripts/extract.d.mts'
Error: error occured in dts build
at Worker. (/Users/kyank/Developer/unified-home/node_modules/tsup/dist/index.js:2294:26)
at Worker.emit (node:events:513:28)
at MessagePort. (node:internal/worker:243:53)
at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
at exports.emitMessage (node:internal/per_context/messageport:23:28)
DTS Build error
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
```
If I re-run the build without deleting the **dist** directory first, the error does not re-occur. If I remove the `scripts/extract.ts` entry module from my project, the same error occurs with a different script:
```
⋮
ESM dist/integrations/webpack-plugin.mjs 2.93 KB
ESM dist/compiledLocales/lv.mjs 6.08 KB
ESM dist/imperativeAPI/formatDate.mjs 166.00 B
ESM dist/compiledLocales/et.mjs 4.54 KB
ESM dist/compiledLocales/tl.mjs 4.53 KB
ESM dist/integrations/webpack.mjs 328.00 B
ESM ⚡️ Build success in 172ms
DTS Build start
Error: ENOENT: no such file or directory, chmod '/Users/kyank/Developer/unified-home/packages/i18n-react-intl/dist/scripts/smartlingPush.d.mts'
Error: error occured in dts build
at Worker. (/Users/kyank/Developer/unified-home/node_modules/tsup/dist/index.js:2294:26)
at Worker.emit (node:events:513:28)
at MessagePort. (node:internal/worker:243:53)
at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
at exports.emitMessage (node:internal/per_context/messageport:23:28)
DTS Build error
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
```
I've tried and failed to reproduce this in a toy project, where I guess the generation of **.d.(m)ts** files runs much more quickly, and therefore all of those files are generated before tsup tries to **chmod** those with shebangs at the top.
Unless I'm mistaken, the **.d.(m)ts** files for shebang scripts don't actually need to be **chmod +x**; only the actual **.(m)js** files need to be made executable. Could this be fixed by excluding the type definition files from the shebang plug-in?
Contributor guide
Research direction
Start at tsup's shebang plug-in and DTS build/chmod handling, using the clean-dist build described in the issue with scripts/extract.ts or another shebang entry module. Check whether generated .d.ts/.d.mts paths can be chmodded before they exist; done means the clean build completes without ENOENT while executable output files still receive the intended handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100