@swc-node/register/esm doesn't recognize `.ts` file
Reproduction Procedure
- Clone this
yarnyarn dev
- Version
node: 14.18.3@swc-node/register: 1.6.0 ~ 1.6.4
- Executed Prompt:
SWCRC=true node --loader @swc-node/register/esm index.ts - Note that
< 1.6, this behavior fall back into #704
.swcrc
{
"jsc": {
"baseUrl": ".",
"parser": {
"syntax": "typescript",
"tsx": true,
"dynamicImport": true
},
"target": "es5"
},
"module": {
"type": "es6"
}
}
Symptoms
yarn run v1.22.19
$ SWCRC=true node --loader @swc-node/register/esm index.ts
(node:19817) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
internal/process/esm_loader.js:74
internalBinding('errors').triggerUncaughtException(
^
[Error: ENOENT: no such file or directory, open '/home/sekyu-kwon/temp/index.ts.mjs'] {
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '/home/my-name/temp/index.ts.mjs'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
As you can see, it doesn't recognize .ts. Also same with .mts.
Is it related to .swcrc recognition issues like #701 ?
same here
same here, any news ?
same issue. mac ok, liunx error
@3lang3 Do you use the same Node versions on both platforms? I see the original issue is using Node 14 which is not a supported LTS release anymore.
this issue occurs on node v20.8.0
@Brooooooklyn After looking into the sources, I found that (at least under windows) the following if clause is causing the issue: https://github.com/swc-project/swc-node/blob/cc3d1da4f732e21c64e749766328705d4f6cfad5/packages/register/register.ts#L69-L73 The compile method of the loader is not transpiling the source file at all, since the filename and the included files provided by the tsconfig options are never equal.
Removing the if-clause makes it work as expected. But after doing some benchmarks with the ESM loaders from @swc-node and @esbuild-kit, @esbuild-kit was almost twice as fast as @swc-node. So I'm definitely sticking with @esbuild-kit..
I can confirm that @philSixZero finding is the same issue for Windows. In my case when there are multiple workspaces in a project. I have a subproject which requires to load their own tsconfig.json. I ended up using dotenv-cli to set the project variable for a Yarn workspace path e.g. TS_NODE_PROJECT=$INIT_CWD/tsconfig.json, however only in linux it works since the url needs this fix as well https://github.com/swc-project/swc-node/pull/754
@Brooooooklyn @Phryxia I think that issue has been resolved via this commit
I can confirm that it is a windows issue. I have tested this on Linux, Mac and Windows. If tsconfig.json exists in subfolder of a workspace it throws an error. If not tsconfig.json exists it runs fine even on Windows.
node --no-warnings=ExperimentalWarning --loader @swc-node/register/esm src/server.ts
"@swc-node/register": "^1.8.0"
node 20.11.1
@nnnnoel Does that fix this as well?
This is my dev script to run the dev server
"dev": "node --watch --no-warnings=ExperimentalWarning --loader @swc-node/register/esm src/index.ts",
It works perfectly fine.