For question about SWC (Speedy Web Compiler), a Rust-based JavaScript compiler.
Questions tagged [swc-compiler]
70 questions
3
votes
1 answer
TypeError [ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module "file:///path/to/data.json" needs an import assertion of type "json"
I'm trying to import JSON in nodejs.
// tsconfig.json
...
"lib": ["es2022"],
"target": "es2022",
"module": "nodenext",
"moduleResolution": "node",
...
"resolveJsonModule": true,
...
// .swcrc.json
...
"target": "es2022",
...
…
user16435030
3
votes
1 answer
Jest: How to transform import.meta.url using Next 12 with SWC
I am using Jest in a Next.js 12 App with the Rust Compiler.
Since I'm using WebWorkers I have a file in which I use import.meta.url. to construct the worker
The problem with that is, that Jest will throw an error stating I can't use import.meta.url…

Maxe
- 83
- 7
3
votes
1 answer
Angular: Component is not resolved when using Speedy Web Compiler (SWC) for TestBed tests
The tests in my Nx Angular 10 repo have been running very slow so I decided to switch from using jest-ts to @swc/jest.
jest.presets.ts
const nxPreset = require('@nrwl/jest/preset');
module.exports = {
...nxPreset,
resolver:…

Alessandro Kreslin
- 269
- 1
- 3
- 15
3
votes
1 answer
Cannot generate Jest coverage report
I am working on a Next.js project in Typescript and am currently using the SWC compiler. As a result, I'm using @swc/jest for my tests. All my tests are passing, but the coverage report always comes back empty. Here's what my jest.config.js looks…

skon182
- 71
- 1
- 7
3
votes
0 answers
How to transpile node_modules with Turborepo and SWC
next-transpile-modules works great for Next projects, but how do I transpile modules for a raw SWC build??? I stumped
Repo: https://github.com/deltaepsilon/script-kitty
I started from a Turborepo base and exported two packages, ui and command-k…

Chris Esplin
- 842
- 9
- 16
2
votes
1 answer
How to access a parameter passed from Next.js configuration inside a SWC compiler plugin?
I'm working on a plugin for the SWC compiler and I'm trying to pass a parameter from the Next.js configuration to the plugin. However, I'm having trouble accessing this parameter within the plugin. I've been trying to find a solution for a long…

Roman
- 175
- 2
- 3
- 15
2
votes
1 answer
Stubbing exported function with sinon, mocha, and swc fails
I am trying to stub the function exported from my ES module.
I used wildcard import(import * as) to stub it, and it works when ts-node is used for transpiling(mocha --require ts-node/register */**/*.spec.ts).
But when swc is used, it fails with the…

Jaemin Choi
- 55
- 5
2
votes
3 answers
Next deployment fails only on Amplify
I am trying to deploy Next.js app on AWS Amplify but it keep fails.
Build worked perfectly fine in local environment and I even succeeded to deploy on Vercel.
But it only fails on Amplify :(
I was able to deploy by creating a .babelrc file, but I am…

rohjs
- 21
- 1
- 4
2
votes
0 answers
SWC: module item found but is_es6 is false
I'm trying to move from babel to swc for compiling and bundling a react component library but I have trouble with the configuration.
When I run npm run spack, I get the following error:
thread '' panicked at 'internal error: entered…

JulienR.
- 33
- 3
2
votes
1 answer
is it possible using rust to generate jsx AST?
I'm not familiar with rust and trynna using swc to replace the babel
but I found @swc/core doesn't offer the api to generate code AST, so I want to write one using rust, is it possible to generate jsx ast?

homy
- 311
- 2
- 7
2
votes
3 answers
SWC with JavaScript: How to handle CSS imports and how to absolute imports?
TL;DR
How can you tell SWC to compile CSS files imported in React components?
How can you tell SWC to compile absolute imports in tests and in React components?
Here is a minimal reproducible example.
Context
We're migrating from Babel to SWC. (I…

J. Hesters
- 13,117
- 31
- 133
- 249
2
votes
1 answer
Import JSON file in .ts and compile it with SWC
I have a typescript file that import a json file like this:
import DefaultMapping from "./default.json";
It compile with SWC like this in the js file:
var _defaultJson = require("./default.json");
However, SWC does not copy the JSON file in the…

Martin J
- 2,019
- 1
- 15
- 28
1
vote
0 answers
Cannot import modules in node command
I have this npm command "create-new": "node --no-warnings --loader ts-node/esm tools/createNewCommand.ts" in tools directory. If I try to import from src/ I get this error: CustomError: Cannot find package '@/main.js'. Maybe the way im running the…

user19210100
- 45
- 5
1
vote
1 answer
How to use swc in rust to compile a js/ts file?
I'm trying to compile js/ts inside the Rust code [with SWC][1].
I'm using the following code, but I get an error (see below):
use std::{path::Path, sync::Arc};
use swc::{self, config::Options};
use swc_common::{
GLOBALS,
…

Salesforce Dev
- 11
- 2
1
vote
1 answer
SWC plugins not working / Any plugin I compile breaks Next js
The Next js framework uses the SWC compiler instead of Babel.
I need to write a plugin for SWC. Everything was working fine, but something happened. Now any plugin that I compile on my computer doesn't work in Next js.
I wrote about this many times…

Roman
- 175
- 2
- 3
- 15