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

Incompatible with SWC loader #12371

Closed
3 tasks done
P4sca1 opened this issue Jun 5, 2024 · 6 comments
Closed
3 tasks done

Incompatible with SWC loader #12371

P4sca1 opened this issue Jun 5, 2024 · 6 comments
Assignees
Labels
Package: node Issues related to the Sentry Node SDK Type: Bug

Comments

@P4sca1
Copy link

P4sca1 commented Jun 5, 2024

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

8.7.0

Framework Version

No response

Link to Sentry event

No response

SDK Setup

No response

Steps to Reproduce

node --import @swc-node/register/esm-register --import ./instrument.js ./src/main.ts

Expected Result

The main.ts file should be correctly executed.

Actual Result

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /Users/pascal/code/ips-hosting/api/src/main.ts
    at new NodeError (node:internal/errors:406:5)
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:99:9)
    at defaultGetFormat (node:internal/modules/esm/get_format:142:36)
    at defaultLoad (node:internal/modules/esm/load:120:20)
    at nextLoad (node:internal/modules/esm/hooks:833:28)
    at load (file:///Users/pascal/code/ips-hosting/api/node_modules/.pnpm/@swc-node+register@1.8.0_@swc+core@1.5.24_@swc+helpers@0.3.17__@swc+types@0.1.7_typescript@5.4.5/node_modules/@swc-node/register/esm/esm.mjs:58:16)
    at nextLoad (node:internal/modules/esm/hooks:833:28)
    at load (/Users/pascal/code/ips-hosting/api/node_modules/.pnpm/import-in-the-middle@1.7.4/node_modules/import-in-the-middle/hook.js:343:12)
    at nextLoad (node:internal/modules/esm/hooks:833:28)
    at Hooks.load (node:internal/modules/esm/hooks:416:26) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'

I also tried with import-in-the-middle 1.8.0 without success. Removing the instrument.js import resolves the issue.
Related: swc-project/swc-node#785

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jun 5, 2024
@github-actions github-actions bot added the Package: node Issues related to the Sentry Node SDK label Jun 5, 2024
@timfish
Copy link
Collaborator

timfish commented Jun 5, 2024

Does it work with the loaders the other way around?

node --import ./instrument.js  --import @swc-node/register/esm-register ./src/main.ts

@getsantry getsantry bot removed the status in GitHub Issues with 👀 3 Jun 5, 2024
@timfish timfish self-assigned this Jun 5, 2024
@timfish
Copy link
Collaborator

timfish commented Jun 5, 2024

I can't even get it to work without instrument.js:

With @swc-node/register@1.9.1 and:

node --import @swc-node/register/esm-register ./test.ts

Gives me

node:internal/modules/run_main:115
    triggerUncaughtException(
    ^
Error: Cannot find module '@swc/core'
Require stack:
- /Users/tim/Documents/Repositories/repro/node_modules/@swc-node/core/lib/index.js
- /Users/tim/Documents/Repositories/repro/node_modules/@swc-node/register/lib/register.js
    at Function._resolveFilename (node:internal/modules/cjs/loader:1186:15)
    at Function._load (node:internal/modules/cjs/loader:1012:27)
    at Module.require (node:internal/modules/cjs/loader:1271:19)
    at require (node:internal/modules/helpers:123:16)
    at Object.<anonymous> (/Users/tim/Documents/Repositories/repro/node_modules/@swc-node/core/lib/index.js:4:16)
    at Module._compile (node:internal/modules/cjs/loader:1434:14)
    at Object..js (node:internal/modules/cjs/loader:1518:10)
    at Module.load (node:internal/modules/cjs/loader:1249:32)
    at Function._load (node:internal/modules/cjs/loader:1065:12)
    at Module.require (node:internal/modules/cjs/loader:1271:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/tim/Documents/Repositories/repro/node_modules/@swc-node/core/lib/index.js',
    '/Users/tim/Documents/Repositories/repro/node_modules/@swc-node/register/lib/register.js'
  ]
}

@P4sca1
Copy link
Author

P4sca1 commented Jun 5, 2024

Yes, that's an issue with version 1.9.1. you have to downgrade to 1.9.0.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jun 5, 2024
@P4sca1
Copy link
Author

P4sca1 commented Jun 5, 2024

For reference: swc-project/swc-node#785

@timfish
Copy link
Collaborator

timfish commented Jun 5, 2024

I get the same error with v1.9.0 and v1.8.0 with Node v22

@P4sca1
Copy link
Author

P4sca1 commented Jun 7, 2024

I tested using Node v22.2.0, @swc-node/register 1.9.0, and import-in-the-middle 1.8.0. The order of the loaders indeed makes a difference. Importing the JavaScript module before the SWC loader solves the ERR_UNKNOWN_FILE_EXTENSION issue.
node --env-file=.env --import ./instrument.js --import @swc-node/register/esm-register ./src/main.ts

@P4sca1 P4sca1 closed this as completed Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: node Issues related to the Sentry Node SDK Type: Bug
Projects
Archived in project
Development

No branches or pull requests

2 participants