swc-node
swc-node copied to clipboard
Error when using swc-node esm with mocha
Hello,
I've tried to run mocha tests with swc-node but when i run this command :
TS_NODE_PROJECT=tsconfig.json SWCRC=true NODE_OPTIONS='--loader @swc-node/register/esm' mocha --recursive test
i have the following error:
(node:25077) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("%40swc-node/register/esm", pathToFileURL("./"));'
(Use `node --trace-warnings ...` to show where the warning was created)
node:internal/process/esm_loader:40
internalBinding('errors').triggerUncaughtException(
^
[Error: cannot process file because it's ignored by .swcrc] {
code: 'GenericFailure'
}
I don't understand what is wrong with my .swrc file. This file seems ok because it works well to transpile ts file (swc lib --out-dir dist)
conf files
.swcrc
{
"$schema": "https://json.schemastore.org/swcrc",
"test": ".*\\.(ts|js)$",
"exclude": "(node_modules|dist)",
"sourceMaps": true,
"jsc": {
"parser": {
"syntax": "typescript"
},
"target": "esnext",
"experimental": {
"plugins": [
[
"@swc/plugin-transform-imports",
{
"^(.*?)(\\.ts)$": {
"skipDefaultConversion": true,
"transform": "{{matches.[1]}}.js"
}
}
]
]
}
}
}
tsconfig.json
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"moduleResolution": "Bundler",
"module": "ESNext",
"target": "ESNext",
"outDir": "./dist",
"types": ["node"],
"lib": ["esnext"],
"allowJs": true,
"strict": false,
"sourceMap": true,
"esModuleInterop": true,
"allowImportingTsExtensions": true,
"skipLibCheck": true,
"isolatedModules": true,
"noEmit": true
},
"exclude": ["node_modules", "dist"],
"include": ["lib", "test"]
}
Versions:
node
v18.19.0
npm
"@swc-node/register": "1.9.x",
"@swc/cli": "0.3.12",
"@swc/core": "1.5.7",
"@swc/plugin-transform-imports": "2.0.x",
Any ideas ?
Thanks
should be fixed in 1.10.0