-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Unexpected token errors coming from import-in-the-middle #12422
Comments
Hi @SerenModz21 thanks for writing in and sorry for the troubles! I'm not yet sure how or why this error is thrown, especially because just transpiling with TSC shouldn't have an impact here. To debug this further:
Let's first check if the SDK is set up correctly and go from there. |
I do indeed transpile to ESM. As for installation, that would be the late initialization method. Unfortunately however, I made the mistake of not trying with |
The |
It could be the I guess |
As an update to my previous comment, I have now tried the following three commands:
However, they all show the "unexpected token" error, followed by the node version (20.14.0) and then it finishes executing, as in it just finishes and does not start the actual node app.
My apologies for the delay in mentioning this update. |
In addition, here is the output with debug logs:
|
any update? SENTRY_DEBUG=1 node -r dotenv/config --import @sentry/node/preload .
Sentry Logger [debug]: @opentelemetry/api: Registered a global for diag v1.9.0.
Sentry Logger [log]: [Sentry] Preloaded Http instrumentation
Sentry Logger [log]: [Sentry] Preloaded Express instrumentation
Sentry Logger [log]: [Sentry] Preloaded Connect instrumentation
Sentry Logger [log]: [Sentry] Preloaded Fastify instrumentation
Sentry Logger [log]: [Sentry] Preloaded Hapi instrumentation
Sentry Logger [log]: [Sentry] Preloaded Koa instrumentation
Sentry Logger [log]: [Sentry] Preloaded Nest instrumentation
Sentry Logger [log]: [Sentry] Preloaded Mongo instrumentation
Sentry Logger [log]: [Sentry] Preloaded Mongoose instrumentation
Sentry Logger [log]: [Sentry] Preloaded Mysql instrumentation
Sentry Logger [log]: [Sentry] Preloaded Mysql2 instrumentation
Sentry Logger [log]: [Sentry] Preloaded Postgres instrumentation
Sentry Logger [log]: [Sentry] Preloaded Hapi instrumentation
Sentry Logger [log]: [Sentry] Preloaded Graphql instrumentation
Sentry Logger [log]: [Sentry] Preloaded Redis instrumentation
node:internal/process/esm_loader:34
internalBinding('errors').triggerUncaughtException(
^
SyntaxError [Error]: Unexpected token (13:76)
at pp$4.raise (/path-to-project/node_modules/.pnpm/[email protected]/node_modules/acorn/dist/acorn.js:3560:15)
at pp$9.unexpected (/path-to-project/node_modules/.pnpm/[email protected]/node_modules/acorn/dist/acorn.js:768:10)
at pp$9.semicolon (/path-to-project/node_modules/.pnpm/[email protected]/node_modules/acorn/dist/acorn.js:745:68)
at Parser.parseImport (/path-to-project/node_modules/.pnpm/[email protected][email protected]/node_modules/acorn-import-attributes/lib/index.js:242:12)
at pp$8.parseStatement (/path-to-project/node_modules/.pnpm/[email protected]/node_modules/acorn/dist/acorn.js:944:51)
at pp$8.parseTopLevel (/path-to-project/node_modules/.pnpm/[email protected]/node_modules/acorn/dist/acorn.js:825:23)
at Parser.parse (/path-to-project/node_modules/.pnpm/[email protected]/node_modules/acorn/dist/acorn.js:597:17)
at Function.parse (/path-to-project/node_modules/.pnpm/[email protected]/node_modules/acorn/dist/acorn.js:647:37)
at getEsmExports (/path-to-project/node_modules/.pnpm/[email protected]/node_modules/import-in-the-middle/lib/get-esm-exports.js:37:23)
at getExports (/path-to-project/node_modules/.pnpm/[email protected]/node_modules/import-in-the-middle/lib/get-exports.js:73:12) {
pos: 978,
loc: { line: 13, column: 76 },
raisedAt: 982
}
Node.js v20.12.1 |
I suspect this is caused by a combination of your dependencies and |
@AnthonyDugarte have you tried removing |
@Lms24 that gave me an idea, I have a internal dependency that imports json files: import json from './file.json' with { type: 'json' }; Commented those out and the previous error went away so prob will make them js objects for now. Now I got a different issue, checking that one |
I tried removing the modules integration and also tried commenting out all integrations that I use but unfortuantely, the Here is a small repo that I have setup that reproduces the error: https://github.com/SerenModz21/sentry-error |
Thanks for the repro, super helpful. I managed to track this down and create PR to fix this. I'll update the It's worth noting that this doesn't appear to work: import { name, version } from "../../package.json" with { type: "json" }; The JSON is exported as the default export so you'll need to do: import pkg from "../../package.json" with { type: "json" }; |
I've updated the patch here to include the above linked PR. |
I have just tested the new patch and my application is now able to execute and be used, which is great news! The errors still get logged but I'm assuming that is to be expected right now, until the PRs finish getting merged and released. So that you have some logs of everything: https://gist.github.com/SerenModz21/81b8a593d1935a3de45eaded861f4043 |
|
Ah, that is fine. Im guess it's just a matter of time until the Acorn issue that you made gets addressed? That being the import attribute one. In addition, I would just like to say that I have appreciated your time greatly in helping me resolve the issue I was having - thank you! |
@timfish I'm experiencing a similar issue, do you think this is related? Error: 'import-in-the-middle' failed to wrap 'file:///app/node_modules/zlib-sync/index.js'
at getSource (/app/node_modules/import-in-the-middle/hook.js:304:21)
at async load (/app/node_modules/import-in-the-middle/hook.js:319:26)
at async nextLoad (node:internal/modules/esm/hooks:866:22)
at async Hooks.load (node:internal/modules/esm/hooks:449:20)
at async handleMessage (node:internal/modules/esm/worker:196:18) {
cause: Error: Unexpected closing brace.
at @:4:142
at parseSource (/app/node_modules/cjs-module-lexer/lexer.js:185:17)
at parseCJS (/app/node_modules/cjs-module-lexer/lexer.js:43:5)
at getCjsExports (/app/node_modules/import-in-the-middle/lib/get-exports.js:37:20)
at getExports (/app/node_modules/import-in-the-middle/lib/get-exports.js:100:12)
at async /app/node_modules/import-in-the-middle/lib/get-exports.js:48:28
at async Promise.all (index 0)
at async getCjsExports (/app/node_modules/import-in-the-middle/lib/get-exports.js:40:5)
at async processModule (/app/node_modules/import-in-the-middle/hook.js:131:23)
at async getSource (/app/node_modules/import-in-the-middle/hook.js:269:25)
at async load (/app/node_modules/import-in-the-middle/hook.js:319:26) {
loc: 973
}
} Is this an issue within |
@FozzieHi I think this is just a warning being logged. Does this affect your application otherwise? |
It does seem to yes,
|
@FozzieHi mind opening a new issue? We can dive deeper there. For everyone else: With the newest release of If you upgrade to a fresh install of the latest version of the Node SDK it should use |
@AbhiPrasad Will do, thanks for your work on this though! |
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.8.0
Framework Version
Node v20.14.0
Link to Sentry event
No response
SDK Setup
Steps to Reproduce
I simply had migrated from v7 to v8.
I was using 8.7.0 with
globalThis._sentryEsmLoaderHookRegistered = true;
until the "no such file or directory" got issue, which was the case with 8.8.0. Since installing the update, i commented out that line of code to check if everything had been fixed but i get spammed with the mentioned unexpected token errors.Just like the "no such file or directory" error, i'm just gonna have to keep using
globalThis._sentryEsmLoaderHookRegistered = true;
or just fallback to v7 for the time being.There is #12357 which is quite similar, the difference being that I do not use TSX but the standard TypeScript compiler. Where my startup is simly
tsc && node --enable-source-maps .
. In addition, my project involvesdiscord.js
,@sapphire/framework
, and other sapphire plugins/utilities (eg. decorators)Expected Result
Errors should not appear.
Actual Result
The text was updated successfully, but these errors were encountered: