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

SWC ignore .swcrc config #1856

Open
Kaizer69 opened this issue Aug 5, 2022 · 18 comments
Open

SWC ignore .swcrc config #1856

Kaizer69 opened this issue Aug 5, 2022 · 18 comments

Comments

@Kaizer69
Copy link

Kaizer69 commented Aug 5, 2022

Desired Behavior

When use ts-node, you should use default swcrc that ts-node create, but if is present a .swcrc file, you should use that file.

Is this request related to a problem?

Yes, because if I have a JS file with private members (hash # char), SWC wont compile

@cspotcode
Copy link
Collaborator

What's your .swcrc look like?

@Kaizer69
Copy link
Author

Kaizer69 commented Aug 5, 2022

{
  "$schema": "https://json.schemastore.org/swcrc",
  "exclude": [".*.js$", ".*.map$"], <<<<<<<<<<-------------
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false,
      "dynamicImport": false,
      "privateMethod": true, <<<<<<<<<<-------------
      "functionBind": false,
      "exportDefaultFrom": false,
      "exportNamespaceFrom": false,
      "decorators": true,
      "decoratorsBeforeExport": false,
      "topLevelAwait": false,
      "importMeta": false
    },
  },
}

I try to pure an invalid .swcrc and ts-node start without problems. The configuration is skipped.
I want to exclude JS (that SWC can parse for private methods) or use privateMethod flag of SWC.

Is possibile enable swcrc flag (actually swcrc: false) here?

Here the error using SWC:

........@swc\helpers\lib\_class_check_private_static_access.js:8
        throw new TypeError("Private static access of wrong provenance");
              ^
TypeError: Private static access of wrong provenance

@cspotcode
Copy link
Collaborator

Is there a minimal example of the .js file raising this error?

@Kaizer69
Copy link
Author

Kaizer69 commented Aug 5, 2022

I cannot provide the example, because the JS lib that I've use is highly obfuscated, so it's difficult extract only the private part.

@cspotcode
Copy link
Collaborator

It can be a new one, just needs to be an example that can be used to test with. Requesting a minimal reproducible example is common practice in open-source: https://en.wikipedia.org/wiki/Minimal_reproducible_example

@vinczebalazs
Copy link

vinczebalazs commented Aug 6, 2022

I have the same problem also, any .swcrc config fileis ignored.

@cajoy
Copy link

cajoy commented Aug 23, 2022

The same here

@falkenhawk
Copy link

falkenhawk commented Dec 6, 2022

Is it really necessary for ts-node to tell swc to ignore .swcrc altogether by this setting?
https://github.com/TypeStrong/ts-node/blob/main/src/transpilers/swc.ts#L222

@radriaanse
Copy link

Slightly different use case here, using the .swcrc file to specify path mappings like;

  "jsc": {
    "paths": {
      "@/some/*": ["thing/*"],
    },

ts-node could optionally allow specifying these (or fetching them from the tsconfig.json) but if we could enable loading the .swcrc ts-node doesn't have to be updated every time new options become available in swc.

@mmazzarolo
Copy link

mmazzarolo commented Feb 17, 2023

For what is worth, for a quick patch, changing swcrc: false to true using patch-package is enough to make it work.

Diff here:

diff --git a/node_modules/ts-node/dist/transpilers/swc.js b/node_modules/ts-node/dist/transpilers/swc.js
index eeddd4f..563c253 100644
--- a/node_modules/ts-node/dist/transpilers/swc.js
+++ b/node_modules/ts-node/dist/transpilers/swc.js
@@ -165,7 +165,7 @@ function createSwcOptions(compilerOptions, nodeModuleEmitKind, swcInstance, swcD
                     ignoreDynamic: nodeModuleEmitKind === 'nodecjs',
                 }
                 : undefined,
-            swcrc: false,
+            swcrc: true,
             jsc: {
                 externalHelpers: importHelpers,
                 parser: {

@vagusX
Copy link

vagusX commented Mar 13, 2023

I think it's necessary for ts-node to expose the reading behavior of swc, especially since the @swc/[email protected] version was recently updated with the useDefineForClassFields option enabled by default, which has caused inconsistent compilation behavior for class properties compared to tsc.

@vagusX
Copy link

vagusX commented Mar 17, 2023

Otherwise shall we disable useDefineForClassFields firstly? #1968

@rafaelliu
Copy link

Also interested in this, same issue with useDefineForClassFields. Merging a explicitly defined .swcrc would be nice, but just exposing useDefineForClassFields would do it on my case

lolopinto added a commit to lolopinto/ent that referenced this issue May 10, 2023
uses https://github.com/swc-project/swc-node

fixes #792

cannot use ts-node anymore because it doesn't provide an option for .swcrc
TypeStrong/ts-node#1856

TODO: depends on swc-project/swc#7358 to actually be used

TODO: remove swc-node in examples/simple

TODO: move .swcrc write in generate_ts_code.go into central location
@danielbayerlein
Copy link

Any news?

@tyteen4a03
Copy link

Bump - this prevents us from adopting React 17 Transform as we're unable to override .swcrc.

@sdotson
Copy link

sdotson commented Jan 25, 2024

Also curious

@mkovel
Copy link

mkovel commented May 8, 2024

any news?

@hanseltime
Copy link

I too would like to use the swc but I have multiple prod/dev .swcrc files that I need to be able to indicate. I have gone ahead and implemented a basic PR, however the yarn version is a blocker for me to install and run tests reliably.

#2143

This is an easy win as long as someone can either take over writing the tests or can point me to documentation for setting up and running tests reliably. The PR itself should be pretty innocuous since it's only adding an option argument and defaults back to the original settings if it's not provided.

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