Command line usage of swc after cargo install swc_cli is challenging.
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
Additional context
No response
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.
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?
yes, swcx and swc_cli is identical binary, just difference of distrubition - prior for the env doesn't have node / npm.
I see, thank you 🙌
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.
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 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?
Yes, that appears to be the case, I'll file a new issue here with a repro then, thanks!
I believe this is adequately resolved as installing new experimental binary moved to @swc/cli.
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.