ts-node icon indicating copy to clipboard operation
ts-node copied to clipboard

SWC ignore .swcrc config

Open Kaizer69 opened this issue 3 years ago • 18 comments
trafficstars

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

Kaizer69 avatar Aug 05 '22 17:08 Kaizer69

What's your .swcrc look like?

cspotcode avatar Aug 05 '22 17:08 cspotcode

{
  "$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

Kaizer69 avatar Aug 05 '22 18:08 Kaizer69

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

cspotcode avatar Aug 05 '22 18:08 cspotcode

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.

Kaizer69 avatar Aug 05 '22 19:08 Kaizer69

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

cspotcode avatar Aug 05 '22 19:08 cspotcode

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

vinczebalazs avatar Aug 06 '22 11:08 vinczebalazs

The same here

cajoy avatar Aug 23 '22 10:08 cajoy

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

falkenhawk avatar Dec 06 '22 09:12 falkenhawk

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.

radriaanse avatar Jan 08 '23 16:01 radriaanse

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: {

mmazzarolo avatar Feb 17 '23 21:02 mmazzarolo

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 avatar Mar 13 '23 11:03 vagusX

Otherwise shall we disable useDefineForClassFields firstly? https://github.com/TypeStrong/ts-node/pull/1968

vagusX avatar Mar 17 '23 04:03 vagusX

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

rafaelliu avatar May 09 '23 17:05 rafaelliu

Any news?

danielbayerlein avatar Aug 04 '23 09:08 danielbayerlein

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

tyteen4a03 avatar Sep 17 '23 00:09 tyteen4a03

Also curious

sdotson avatar Jan 25 '24 15:01 sdotson