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

Running a .tsx file in 1.10.0 yields Unknown file extension ".tsx" error #799

Closed
xandris opened this issue Jul 3, 2024 · 0 comments · Fixed by #800
Closed

Running a .tsx file in 1.10.0 yields Unknown file extension ".tsx" error #799

xandris opened this issue Jul 3, 2024 · 0 comments · Fixed by #800

Comments

@xandris
Copy link
Contributor

xandris commented Jul 3, 2024

Here is a minimal repro: https://github.com/xandris/swc-node-esm-tsx-bug

Output from 1.8.x:

$ npm i -D @swc-node/[email protected]
$ npm start
> [email protected] start
> export SWCRC=true NODE_OPTIONS=--import=@swc-node/register/esm-register; node b.ts; node c.tsx

hi

node:internal/modules/run_main:129
    triggerUncaughtException(
    ^
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'react' imported from /Users/aparker/src/test-swc-register/c.tsx
    at packageResolve (node:internal/modules/esm/resolve:854:9)
    at moduleResolve (node:internal/modules/esm/resolve:927:18)
    at defaultResolve (node:internal/modules/esm/resolve:1157:11)
    at nextResolve (node:internal/modules/esm/hooks:866:28)
    at resolve (file:///Users/aparker/src/test-swc-register/node_modules/@swc-node/register/esm/esm.mjs:44:12)
    at nextResolve (node:internal/modules/esm/hooks:866:28)
    at Hooks.resolve (node:internal/modules/esm/hooks:304:30)
    at MessagePort.handleMessage (node:internal/modules/esm/worker:196:24)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:820:20)
    at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28) {
  code: 'ERR_MODULE_NOT_FOUND'
}

This shows the file c.tsx was transpiled and run. React isn't available; that's fine.

Output from 1.10.0:

$ npm i -D @swc-node/[email protected]
$ npm start
> [email protected] start
> export SWCRC=true NODE_OPTIONS=--import=@swc-node/register/esm-register; node b.ts; node c.tsx

hi

node:internal/modules/run_main:129
    triggerUncaughtException(
    ^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".tsx" for /Users/aparker/src/test-swc-register/c.tsx
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:160:9)
    at defaultGetFormat (node:internal/modules/esm/get_format:203:36)
    at defaultLoad (node:internal/modules/esm/load:143:22)
    at async nextLoad (node:internal/modules/esm/hooks:866:22)
    at async load (file:///Users/aparker/src/test-swc-register/node_modules/@swc-node/register/esm/esm.mjs:178:48)
    at async nextLoad (node:internal/modules/esm/hooks:866:22)
    at async Hooks.load (node:internal/modules/esm/hooks:449:20)
    at async MessagePort.handleMessage (node:internal/modules/esm/worker:196:18) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}

This shows c.tsx isn't run at all. b.ts runs, but c.tsx fails.

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

Successfully merging a pull request may close this issue.

1 participant