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 compatibility #1403
Comments
Just define https://swc.rs/docs/configuration/compilation#jsctransformdecoratormetadata in your .swcrc file |
Thank you for your reply. |
Can you give me more information ? Bundler used, config file, etc... |
@GuillaumeCisco try this. {
jsc: {
target: 'es2020',
parser: {
syntax: 'typescript',
dynamicImport: true,
decorators: true
},
transform: {
legacyDecorator: true,
decoratorMetadata: true
},
externalHelpers: true,
keepClassNames: true,
loose: true
}
} @HeadFox for bundling, I recommend using rollup, along with the rollup-plugin-swc3 & rollup-plugin-tsconfig-paths Some config: import { swc } from 'rollup-plugin-swc3';
import { tsConfigPaths } from 'rollup-plugin-tsconfig-paths';
import { nodeResolve } from '@rollup/plugin-node-resolve';
// bypass errors thrown by inversify
const onwarn = (msg, warn) => {
if (!/Circular|The 'this' keyword/.test(msg)) {
warn(msg);
}
};
// ...
{
input: INPUT_FILE,
output: {
file: OUTPUT_FILE,
format: 'cjs'
},
plugins: [
tsConfigPaths({ tsConfigPath: PATH_TO_TSCONFIG }),
nodeResolve(),
swc({
tsconfig: PATH_TO_TSCONFIG,
minify: false, // set to true to minify
jsc: {
target: 'es2020',
parser: {
syntax: 'typescript',
dynamicImport: true,
decorators: true
},
transform: {
legacyDecorator: true,
decoratorMetadata: true
},
externalHelpers: true,
keepClassNames: true,
loose: true
}
})
],
onwarn
}; |
@GuillaumeCisco did you find a solution? I am having the same issue and the I am using Next.js 12 and am attempting to migrate from babel to swc. I get |
@kristiegiles Next12 disabled .swcrc load. But support for emitDecoratorMetadata will be enabled if specified in tsconfig in next Next.js release --> vercel/next.js#32914 |
Thanks! I also tried it without the .swcrc, and that didn't help. I am using Next 12.0.11-canary.11, and I do have |
Normally yes. With also reflect-metadata installed |
That's correct! |
@GuillaumeCisco can you close this Pr ? :) |
have used inversify with swc and it works fine for me |
Problem about transpilation, you need set "target" es2015 or higher in your .swcrc config file. |
The link provided in the first comment worked great. Thank you!!! |
Is inversify compatible with SWC?
From our tests, it looks like the
@inject(...)
decorators are not correctly transpiled.Expected Behavior
Works with swc
Current Behavior
@inject
decorators seems bypassed.Possible Solution
Steps to Reproduce (for bugs)
Context
Your Environment
Stack trace
The text was updated successfully, but these errors were encountered: