Skip to content

SWC exits successfully even though input path does not exist #6725

@bduffany

Description

@bduffany

Describe the bug

When running swc /does/not/exist.ts --out-file foo.js, SWC exits with code 0 and produces an empty .js output file, as though the compilation was successful. It seems like it is treating non-existent files as being empty.

This is misleading, since if we make a typo in the source file name (or inadvertently point to the wrong path, etc.) then SWC will generate an empty JS output file rather than exiting with an error or even a warning.

When executing SWC as part of a larger build, this behavior is extra confusing, since the SWC transpile step will succeed and the rest of the build will proceed as usual, even though there is actually an error.

Input code

No response

Config

No response

Playground link

No response

Expected behavior

SWC should exit with code 1 and say "error: file '/does/not/exist.ts' does not exist."

If this can't be changed due to concerns about breaking existing users, I would love to have a flag that asserts all sources exist. Naming suggestions: --check-inputs, --sources-must-exist, --strict-sources, --no-missing-sources, --disallow-missing-sources etc.

Actual behavior

SWC exits with code 0 and produces empty JS output, and there doesn't appear to be a flag or config option that changes this behavior.

Version

@swc/cli: 0.1.59 @swc/core: 1.3.24

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions