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: Reflect renamed keepImportAssertions configuration option #2056

Closed
felixh10r opened this issue Sep 7, 2023 · 7 comments · Fixed by #2062
Closed

SWC: Reflect renamed keepImportAssertions configuration option #2056

felixh10r opened this issue Sep 7, 2023 · 7 comments · Fixed by #2062

Comments

@felixh10r
Copy link

Desired Behavior

With version 1.3.83, swc renames the experimental configuration option jsc.experimental.keepImportAssertions to jsc.experimental.keepImportAttributes as per swc-project/swc#7914 .

Is this request related to a problem?

All setups with swc > 1.3.82 will fail. This creates a dependency version limitation which should probably be reflected in peerDependencies or simply updated in a new ts-node release.

Additional context

If the solution is to simply change the name of the property, I'm happy to open a PR.

@felixh10r
Copy link
Author

since the swc config option is experimental, it was changed in a patch update to @swc/core, which may be updated by developers without knowing about the breaking behavior.

@meabed
Copy link

meabed commented Sep 7, 2023

I tried commenting in SWC :) but no luck 😢

@isaacs
Copy link
Contributor

isaacs commented Sep 7, 2023

Actually, we should just remove that option from ts-node, I think. swc only emits import .. from .. with {}, not import .. from .. assert {}, and no version of node supports that syntax.

1.3.83 adds emitAssertForImportAttributes, but it doesn't do that, so typescript currently actually relying on import/assert is (a) currently broken when using swc with ts-node, and (b) not likely to work any time soon.

Better to just have it strip the attributes, imo.

isaacs added a commit to isaacs/ts-node that referenced this issue Sep 7, 2023
This removes support for keeping import assertions, which were broken in
swc at some point, and unconditionally transpiled into import
attributes. (Ie, `import/with` instead of `import/assert`.)

No version of node supports import attributes with this syntax yet, so
anyone using swc to import json in ESM is out of luck no matter what.

And swc 1.3.83 broke the option that ts-node was using. The position of
the swc project is that experimental features are not supported, and may
change in patch versions without warning, making them unsafe to rely on
(as evidenced here, and the reason why this behavior changed
unexpectedly in the first place).

Better to just not use experimental swc features, and let it remove
import assertions rather than transpile them into something that node
can't run.

Fix: TypeStrong#2056
@isaacs
Copy link
Contributor

isaacs commented Sep 7, 2023

emitAssertForImportAttributes would be nice, but I'd still recommend waiting until it's promoted out of experimental status.

@RobinTail
Copy link

Perhaps It would be convenient to have an ability to configure swc options in tsconfig besides just having

"swc": true

ndelangen added a commit to storybookjs/storybook that referenced this issue Sep 12, 2023
This is the error that was happening:
```
/Users/me/Projects/Storybook/core/scripts/node_modules/ts-node/src/transpilers/swc.ts:262
      throw new Error(
            ^
Error: @swc/core threw an error when attempting to validate swc compiler options.
You may be using an old version of swc which does not support the options used by ts-node.
Try upgrading to the latest version of swc.
Error message from swc:
Failed to deserialize buffer as swc::config::Options
JSON: {"sourceMaps":true,"module":{"noInterop":false,"type":"commonjs","strictMode":true,"ignoreDynamic":false},"swcrc":false,"jsc":{"parser":{"syntax":"typescript","tsx":false,"dynamicImport":true,"importAssertions":true},"target":"es2020","transform":{"legacyDecorator":true,"react":{"throwIfNamespace":false,"useBuiltins":false}},"keepClassNames":true,"experimental":{"keepImportAssertions":true}}}

Caused by:
    unknown field `keepImportAssertions`, expected one of `plugins`, `keepImportAttributes`, `emitAssertForImportAttributes`, `cacheRoot`, `disableBuiltinTransformsForInternalTesting` at line 1 column 395
    at createVariant (/Users/me/Projects/Storybook/core/scripts/node_modules/ts-node/src/transpilers/swc.ts:262:13)
    at createSwcOptions (/Users/me/Projects/Storybook/core/scripts/node_modules/ts-node/src/transpilers/swc.ts:211:25)
    at create (/Users/me/Projects/Storybook/core/scripts/node_modules/ts-node/src/transpilers/swc.ts:56:41)
    at createTranspiler (/Users/me/Projects/Storybook/core/scripts/node_modules/ts-node/src/index.ts:784:16)
    at createTranspileOnlyGetOutputFunction (/Users/me/Projects/Storybook/core/scripts/node_modules/ts-node/src/index.ts:1341:28)
    at createFromPreloadedConfig (/Users/me/Projects/Storybook/core/scripts/node_modules/ts-node/src/index.ts:1404:34)
    at phase4 (/Users/me/Projects/Storybook/core/scripts/node_modules/ts-node/src/bin.ts:543:44)
    at bootstrap (/Users/me/Projects/Storybook/core/scripts/node_modules/ts-node/src/bin.ts:95:10)
    at main (/Users/me/Projects/Storybook/core/scripts/node_modules/ts-node/src/bin.ts:55:10)
    at Object.<anonymous> (/Users/me/Projects/Storybook/core/scripts/node_modules/ts-node/src/bin.ts:800:3)
```
@meyfa
Copy link

meyfa commented Sep 12, 2023

I think a way of configuring SWC would definitely be nice long-term. For now, I would like to get SWC >=1.3.83 to not fail our CI builds with ts-node. It seems like PR #2057 would achieve this. Is there any way to help moving this forward? @cspotcode

@MuTsunTsai
Copy link

Experiencing the same issue as well. Have to stay at SWC 1.3.82 for now.

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

Successfully merging a pull request may close this issue.

6 participants