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-node/register/esm doesn't recognize .ts file #710

Open
Phryxia opened this issue Apr 19, 2023 · 10 comments
Open

@swc-node/register/esm doesn't recognize .ts file #710

Phryxia opened this issue Apr 19, 2023 · 10 comments

Comments

@Phryxia
Copy link

Phryxia commented Apr 19, 2023

Reproduction Procedure

  1. Clone this
  2. yarn
  3. yarn dev

.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 ?

@huseeiin
Copy link

same here

@sebaplaza
Copy link

same here, any news ?

@3lang3
Copy link

3lang3 commented Sep 20, 2023

same issue.
mac ok, liunx error

@fatso83
Copy link

fatso83 commented Sep 20, 2023

@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.

@iambumblehead
Copy link

this issue occurs on node v20.8.0

@philSixZero
Copy link

philSixZero commented Oct 10, 2023

@Brooooooklyn After looking into the sources, I found that (at least under windows) the following if clause is causing the issue:

if (
PLATFORM === 'win32' &&
(options.files as string[]).every((file) => filename !== resolve(process.cwd(), file))
) {
return sourcecode

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..

@psychobolt
Copy link

psychobolt commented Feb 9, 2024

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 #754

@nnnnoel
Copy link

nnnnoel commented Feb 19, 2024

@Brooooooklyn @Phryxia I think that issue has been resolved via this commit

@c3cris
Copy link

c3cris commented Feb 23, 2024

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?

@guptaashwanee
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests