swc icon indicating copy to clipboard operation
swc copied to clipboard

Command line usage of swc after cargo install swc_cli is challenging.

Open joshcartme opened this issue 3 years ago • 8 comments

Describe the bug

If you have done cargo install swc_cli and then try to:

npx swc ./some-file.js

it fails because npx now looks to the swc command from cargo, rather than swc/cli from npm.

You can begin to work around this by using the command from cargo directly, e.g.:

swc compile ./some-file.js

but this fails if you try to specify an .swcrc, for example:

swc compile ./some-file.js --config-file .swcrc

it fails with:

Error: Failed to parse config file

Caused by:
    data did not match any variant of untagged enum ConfigFile

The same config file works fine if you use the binary installed by npm more directly:

npx /full/path/to/node_modules/.bin/swc ./some-file.js --config-file .swcrc

Input code

No response

Config

{
    "jsc": {
        "target": "es2017"
    }
}

Playground link

No response

Expected behavior

I would expect the config file to work with the swc_cli installed with cargo.

Actual behavior

No response

Version

[email protected]

Additional context

No response

joshcartme avatar May 11 '22 23:05 joshcartme

would you able to uninstall swc_cli from cargo, then use npx swcx with @swc/core instead? it's prepared for those purpose as you said conflicting cli binary name can cause some problems. swc_cli was introduced for non-node environment, but at the same time we didn't ship those binary to actual npm pkg, but now @swc/core have it shipped together.

kwonoj avatar May 11 '22 23:05 kwonoj

Oh, got it, thanks! so if I uninstall it from cargo, I can then create plugins with npx swcx? Could I suggest adding something to the plugin getting started docs to that affect?

joshcartme avatar May 11 '22 23:05 joshcartme

yes, swcx and swc_cli is identical binary, just difference of distrubition - prior for the env doesn't have node / npm.

kwonoj avatar May 11 '22 23:05 kwonoj

I see, thank you 🙌

joshcartme avatar May 11 '22 23:05 joshcartme

I'm removing this from bug but put into enhancement, this is mostly due to current situation where we have @swc/cli and experiemental swcx both. We'll likely need to realign once native cli binary gets progress, but this won't block anyone for now afaik.

kwonoj avatar May 20 '22 19:05 kwonoj

I'm trying to use the native rust swc_cli under Bazel (much faster when we spawn hundreds of processes), hitting that same error as above when using --config-file. @kwonoj should I file separate issues for that? I realize you don't really support using the Rust swc_cli directly yet.

alexeagle avatar Jul 03 '22 17:07 alexeagle

@alexeagle it sounds like a different issue, as bazel shouldn't rely on any global path resolution. Am I missing something? So the issue is swcx (native rust cli) doesn't work with --config-file options?

kwonoj avatar Jul 04 '22 18:07 kwonoj

Yes, that appears to be the case, I'll file a new issue here with a repro then, thanks!

alexeagle avatar Jul 06 '22 03:07 alexeagle

I believe this is adequately resolved as installing new experimental binary moved to @swc/cli.

kwonoj avatar Jul 26 '23 16:07 kwonoj

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

swc-bot avatar Aug 28 '23 00:08 swc-bot