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

Error when using v8 lambda layer #12012

Closed
3 tasks done
JoaquinFernandez opened this issue May 13, 2024 · 8 comments · Fixed by #12021
Closed
3 tasks done

Error when using v8 lambda layer #12012

JoaquinFernandez opened this issue May 13, 2024 · 8 comments · Fixed by #12021

Comments

@JoaquinFernandez
Copy link

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/aws-serverless

SDK Version

8.0.0

Framework Version

No response

Link to Sentry event

No response

SDK Setup

No response

Steps to Reproduce

I imported (actually just switched) from one layer (version 235 -> version 240) which changes from @sentry/serverless 7.113.0 to @sentry/aws-serverless 8.0.0.

I updated the NODE_OPTIONS from -r @sentry/serverless/dist/awslambda-auto to -r @sentry/aws-serverless/dist/awslambda-auto
I also updated calls to the SDK, but it doesn't get that far.

Expected Result

The SDK is loaded and initialized as expected

Actual Result


node:internal/modules/cjs/loader:562
--
throw e;
^
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/awslambda-auto' is not defined by "exports" in /opt/nodejs/node_modules/@sentry/aws-serverless/package.json
at new NodeError (node:internal/errors:387:5)
at throwExportsNotFound (node:internal/modules/esm/resolve:365:9)
at packageExportsResolve (node:internal/modules/esm/resolve:649:3)
at resolveExports (node:internal/modules/cjs/loader:556:36)
at Function.Module._findPath (node:internal/modules/cjs/loader:596:31)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1014:27)
at Function.Module._load (node:internal/modules/cjs/loader:873:27)
at internalRequire (node:internal/modules/cjs/loader:169:19)
at Module._preloadModules (node:internal/modules/cjs/loader:1375:5)
at loadPreloadModules (node:internal/bootstrap/pre_execution:583:5) {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

@lforst
Copy link
Member

lforst commented May 14, 2024

Hi, sorry that you are running into this. I think this is a documentation issue. Can you try pointing it to -r @sentry/aws-serverless/cjs/awslambda-auto?

@s1gr1d
Copy link
Member

s1gr1d commented May 14, 2024

Tell us if the suggestion from @lforst worked for you. If this doesn't work, we'll add a fix which will be added in an upcoming version.

@JoaquinFernandez
Copy link
Author

Hi!

Same issue:

node:internal/modules/cjs/loader:562
--
throw e;
^
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './cjs/awslambda-auto' is not defined by "exports" in /opt/nodejs/node_modules/@sentry/aws-serverless/package.json
at new NodeError (node:internal/errors:387:5)
at throwExportsNotFound (node:internal/modules/esm/resolve:365:9)
at packageExportsResolve (node:internal/modules/esm/resolve:649:3)
at resolveExports (node:internal/modules/cjs/loader:556:36)
at Function.Module._findPath (node:internal/modules/cjs/loader:596:31)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1014:27)
at Function.Module._load (node:internal/modules/cjs/loader:873:27)
at internalRequire (node:internal/modules/cjs/loader:169:19)
at Module._preloadModules (node:internal/modules/cjs/loader:1375:5)
at loadPreloadModules (node:internal/bootstrap/pre_execution:583:5) {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'

@JoaquinFernandez
Copy link
Author

FYI, I also tried as documented here:
https://github.com/getsentry/sentry-javascript/tree/develop/packages/aws-serverless

With -r @sentry/aws-serverless/build/npm/cjs/awslambda-auto and same error.

@Lms24
Copy link
Member

Lms24 commented May 14, 2024

We already merged #12021 to fix this and we'll release it tomorrow with version 8.1.0. Thanks for reporting though!

So hopefully, with 8.1.0, any of these two options should work:

  • -r @sentry/aws-serverless/dist/awslambda-auto <-- same as in v7 except for the package name change
  • -r @sentry/aws-serverless/awslambda-auto <-- a bit cleaner and probably how we'll document this in the future.

@igorlamos
Copy link

The official Sentry v8 layer still doesn't work for me ...

Cannot find package '@sentry/aws-serverless' imported from /var/task/index.mjs
Did you mean to import "@sentry/aws-serverless/build/npm/cjs/index.js"?

... and I didn't mean to import @sentry/aws-serverless/build/npm/cjs/index.js.

I'm using the Layer version 256 in the us-east-1 region. When I get that layer, the package.json contains:

  "main": "build/npm/cjs/index.js",
  "types": "build/npm/types/index.d.ts",
  "exports": {
    "./package.json": "./package.json",
    ".": {
      "import": {
        "types": "./build/npm/types/index.d.ts",
        "default": "./build/npm/esm/index.js"
      },
      "require": {
        "types": "./build/npm/types/index.d.ts",
        "default": "./build/npm/cjs/index.js"
      }
    },
    "./import": {
      "import": {
        "default": "./build/import-hook.mjs"
      }
    },
    "./loader": {
      "import": {
        "default": "./build/loader-hook.mjs"
      }
    },
    "./awslambda-auto": {
      "require": {
        "default": "./build/npm/cjs/awslambda-auto.js"
      }
    },
    "./dist/awslambda-auto": {
      "//": "@deprecated Use `./awslambda-auto` instead",
      "require": {
        "default": "./build/npm/cjs/awslambda-auto.js"
      }
    }
  },

but the actual structure (all that's in the layer) is:
CleanShot 2024-07-06 at 17 54 43@2x

The ./build/npm/esm folder is completely missing, with some other files too ...

I'd say there's some problem with how the Sentry Lambda layer is being created, because when I create my own – everything works as expected.

Thank you!

@Lms24
Copy link
Member

Lms24 commented Jul 8, 2024

Hey @igorlamos I just tested the layer in our E2E tests and I believe the structure is correct for CommonJS (CJS) apps.

... and I didn't mean to import @sentry/aws-serverless/build/npm/cjs/index.js.

Are you running your lambdas in ESM mode? If so, the lambda layer does not support ESM mode and it's questionalbe when we'll be able to do so due to some limitations with OpenTelemetry and bundling code like we do in the CJS layer. In this case, you'll need to install the SDK manually with NPM. I'm currently working on this (tracked in #12409) along with some better documentation to point this out more clearly.

@igorlamos
Copy link

Hey @Lms24 – that makes sense. Thanks for the clarification.

Are you running your lambdas in ESM mode?

Yes – I'm running my lambdas in ESM, therefore the problem. I was not able to find in the Docs that the Layer doesn't support ESM. So that's OK now.

I was just a little confused as package.json is referencing files in exports that do not exist.

I'm also not aware of the consequences/limitations with OpenTelemetry, so in case that's the reason – that's fine too 👍

I was able to easily overcome the "issue" on my end by building my own layer and sharing that among all of the accounts where I need it.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants