Skip to content

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

@bbugh

Description

@bbugh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions