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

Use .swcrc with the swc transpiler #1796

Closed
davidtheclark opened this issue Jun 13, 2022 · 6 comments
Closed

Use .swcrc with the swc transpiler #1796

davidtheclark opened this issue Jun 13, 2022 · 6 comments

Comments

@davidtheclark
Copy link

Desired Behavior

When I use the bundled swc transpiler, I'd like it to read configuration from my .swcrc file. Instead, it looks like the plugin creates its own swc config based on ts-node's configuration. This means I need to put my swc configuration in two places, instead just in my .swcrc file.

Is this request related to a problem?

Just configuration duplication.

Alternatives you've considered

Using swc packages directly instead of ts-node's swc transpiler. But ts-node's source maps work in my context (VS Code debugger) and swc's do not (as far as I can tell), so I want to stick with ts-node.

Additional context

ts-node was complaining about import statements not being legal. It took me a bit to realize this meant it wasn't reading my .swcrc file, which specified "module": { "type": "commonjs" } }. To fix this, I set TS_NODE_COMPILER_OPTIONS='{"module":"commonjs"}'.

@cspotcode
Copy link
Collaborator

I'd accept a PR that adds this as an option, but I still want the default to be zero-config.

In your case, you shouldn't need to specify module: {type: "commonjs" } in .swcrc if you package.json and tsconfig.json are configured correctly. I feel like there might be a more pragmatic solution here, maybe some tsconfig confusion that we can clear up.

@cspotcode cspotcode added the research Needs design work, investigation, or prototyping. Implementation uncertain. label Jun 13, 2022
@davidtheclark
Copy link
Author

I think the problem is that I'd rather not have a tsconfig.json file in addition to an .swcrc file.

I'd accept a PR that adds this as an option, but I still want the default to be zero-config.

That sounds reasonable 👍

@cspotcode
Copy link
Collaborator

cspotcode commented Jun 15, 2022 via email

@davidtheclark
Copy link
Author

davidtheclark commented Jun 15, 2022

OK -- yeah, maybe the root problem is that swc tools do not read tsconfig.json (unless I'm doing it wrong). And I understand that that's not your problem. I will keep fiddling, and if I can't figure something out may try to come up with a PR.

@ShravanSunder
Copy link

ShravanSunder commented Jun 17, 2022

@cspotcode
Copy link
Collaborator

@davidtheclark it looks like your problem will be solved by adopting a tsconfig.json. ts-node will read it and behave accordingly. If you run into a situation where you feel like you need two different tsconfig files, because you already have a tsconfig for some other purpose, and yet you need ts-node or swc to behave differently than what is in your tsconfig, then you may want to know that ts-node allows overriding options within your tsconfig, using a "ts-node" sub-object. In general, everything can be configured in that one file: https://typestrong.org/ts-node/docs/configuration#via-tsconfigjson-recommended

This setup is simple enough when done correctly. If you run into any trouble, please either ask on the Typescript Discord or start a discussion thread.

I'll go ahead and close this ticket, but we can accept a PR (with proper tests!) that adds swcrc support as an option. So if you decide you want to implement that, feel free to open a new issue to discuss the best approach.

@cspotcode cspotcode removed the research Needs design work, investigation, or prototyping. Implementation uncertain. label Jun 17, 2022
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

3 participants