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

Using --project switch breaks when tsconfig.json does not specify outDir #838

Open
bbugh opened this issue Jul 19, 2024 · 0 comments
Open

Comments

@bbugh
Copy link

bbugh commented Jul 19, 2024

Given a minimal tsconfig.json:

{}

When running npx sucrase -p ., an error message occurs:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined
    at Object.stat (node:fs:1615:10)
    at /project/path/node_modules/mz/fs.js:58:8
    at new Promise (<anonymous>)
    at exports.exists (/project/path/node_modules/mz/fs.js:57:10)
    at runGlob (/project/path/node_modules/sucrase/dist/cli.js:186:26)
    at async buildDirectory (/project/path/node_modules/sucrase/dist/cli.js:299:13) {
  code: 'ERR_INVALID_ARG_TYPE'

The problem occurs here

sucrase/src/cli.ts

Lines 186 to 188 in 61c05e1

if (!(await exists(options.outDirPath))) {
await mkdir(options.outDirPath);
}

because outDirPath does not have a default value.

This error message is confusing and it took me digging in the sucrase code to find the answer.

I don't know what the right answer is for how it should behave, but some ideas are :

  1. Perhaps outDirPath can behave similarly to tsc, which compiles files next to the originals if compilerOptions.outDir is not defined
  2. Use the default of the common "dist" folder
  3. Print a more useful error that the outDir is not defined in tsconfig.json
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

1 participant