-
-
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
Sentry.captureException is not a function #7441
Comments
Hey @maxpain thanks for writing in! As per https://unpkg.com/@sentry/serverless@7.42.0/cjs/index.js we should be exporting Did this start happening with the latest version? Are you using some bundling process when deploying to your serverless function? |
Hello. I don't know, I just switched from @sentry/node to @sentry/serverless in my Google Cloud Function |
What happens if you import via a Our serverless SDK just re-exports the Node SDK:
What happens if you explicitly import const { captureException } = require('@sentry/serverless'); Are you able to provide a reproduction of some kind to help us debug further? |
const { captureException } = require('@sentry/serverless')
captureException(new Error('test')) maxpain@Maksims-MacBook-Pro-2 webhooks % npx env-cmd ts-node --esm ./src/handle-gamemoney.ts
ReferenceError: require is not defined in ES module scope, you can use import instead
at file:///Users/maxpain/dev/gptask/webhooks/src/handle-gamemoney.ts:1:30
at ModuleJob.run (node:internal/modules/esm/module_job:193:25) |
This error makes sense, since you were calling I tried reproducing this here: https://github.com/AbhiPrasad/GH-7441-captureException-not-a-function, but works fine for me. Are you sure you've installed your packages correctly? |
@AbhiPrasad Adding "type": "module" to package.json, which makes this package an ESM module, causes the error. |
Ah yeah I forgot to remove the require call: diff --git a/src/handle-gamemoney.ts b/src/handle-gamemoney.ts
index 4545802..b6db55e 100644
--- a/src/handle-gamemoney.ts
+++ b/src/handle-gamemoney.ts
@@ -1,2 +1,2 @@
-const { captureException } = require("@sentry/serverless");
+import { captureException } from "@sentry/serverless";
captureException(new Error("test")); Now we should be using esm across the board! Running |
@AbhiPrasad |
Thanks, was able to reproduce! I don't quite understand why this is happening though because we ship esm:
For some reason, The work around is like so
|
No, the problem is not in maxpain@Maksims-MacBook-Pro-2 GH-7441-captureException-not-a-function % npx tsc
maxpain@Maksims-MacBook-Pro-2 GH-7441-captureException-not-a-function % node .build/index.js
file:///Users/maxpain/dev/GH-7441-captureException-not-a-function/.build/index.js:2
Sentry.captureException(new Error("test"));
^
TypeError: Sentry.captureException is not a function
at file:///Users/maxpain/dev/GH-7441-captureException-not-a-function/.build/index.js:2:8
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
Node.js v19.7.0 |
By the way, this approach also doesn't work: import { captureException } from "@sentry/serverless";
captureException(new Error("test")); maxpain@Maksims-MacBook-Pro-2 GH-7441-captureException-not-a-function % npx ts-node --esm src/index.ts
file:///Users/maxpain/dev/GH-7441-captureException-not-a-function/src/index.ts:1
import { captureException } from "@sentry/serverless";
^^^^^^^^^^^^^^^^
SyntaxError: Named export 'captureException' not found. The requested module '@sentry/serverless' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from '@sentry/serverless';
const { captureException } = pkg;
at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:189:5) |
yes the thing is with your tsconfig setup in general - which is detailed in TypeStrong/ts-node#935 The problem is that I guess the newest node versions expect We expose esm -https://unpkg.com/@sentry/serverless@7.43.0/esm/index.js, but I guess typescript is not respecting that and expecting something else :/ |
But I don't have any problems with |
Ah I see what the issue is now! We might be incorrectly setting the |
Basically, everything is the same except for "engines.node" field. |
I wonder if the usage of the namespace imports is causing issues: sentry-javascript/packages/serverless/src/index.ts Lines 2 to 4 in d6561b8
|
It is causing issues! It's causing the node exports to go under
|
Thanks for sticking with me @maxpain and helping debug, appreciate the help a lot! I wonder now how we should solve this 🤔. Is there a good way to mix namespace imports while preserving the wildcard export of the node package. |
Opened #7457 to fix! |
Thanks! |
@maxpain fix is merged, will be part of the next SDK release. In the meantime, you can fall back to importing and using the Again, appreciate the help debugging, couldn't have figured it out without your help! |
@AbhiPrasad Hi! I think this is relevant for |
Hey. I am also experiencing something of that sort. basically I have this sentry.ts plugin
This works perfectly on dev environment, but when I build the nuxt application then sentry starts to serve captureMessage .. captureException etc functions from under default. . console.logged the Sentry on a built app.
console.logged sentry in dev environment.
|
@KarelVendla please open a new GH issue - we need more details around SDK version and nuxt/vite version to help debug. |
Is there an existing issue for this?
How do you use Sentry?
Self-hosted/on-premise
Which SDK are you using? If you use the CDN bundles, please specify the exact bundle (e.g.
bundle.tracing.min.js
) in your SDK setup.@sentry/serverless
SDK Version
7.43.0
Framework Version
No response
Link to Sentry event
No response
SDK Setup
Steps to Reproduce
Sentry.captureException(new Error('test'))
Expected Result
Don't crash
Actual Result
Crash
The text was updated successfully, but these errors were encountered: