trigger.dev icon indicating copy to clipboard operation
trigger.dev copied to clipboard

bug: Cannot get final name for export 'SEMATTRS_HTTP_STATUS_CODE'

Open rafalzawadzki opened this issue 1 year ago • 7 comments

Provide environment information

System: OS: macOS 14.4 CPU: (12) arm64 Apple M2 Max Memory: 1.51 GB / 32.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 21.4.0 - ~/.nvm/versions/node/v21.4.0/bin/node Yarn: 1.22.21 - /opt/homebrew/bin/yarn npm: 10.2.4 - ~/.nvm/versions/node/v21.4.0/bin/npm pnpm: 9.14.2 - ~/Library/pnpm/pnpm bun: 1.0.6 - ~/.bun/bin/bun

Describe the bug

After upgrading to @trigger.dev/[email protected] I started getting the following error when building a NextJS 14 project:

./node_modules/.pnpm/@[email protected][email protected]/node_modules/@trigger.dev/sdk/dist/esm/v3/retry.js + 6 modules
Cannot get final name for export 'SEMATTRS_HTTP_STATUS_CODE' of ./node_modules/.pnpm/@[email protected]/node_modules/@opentelemetry/semantic-conventions/build/esm/index.js
./node_modules/.pnpm/@[email protected][email protected]/node_modules/@trigger.dev/sdk/dist/esm/v3/retry.js + 6 modules
Cannot get final name for export 'SEMATTRS_HTTP_STATUS_CODE' of ./node_modules/.pnpm/@[email protected]/node_modules/@opentelemetry/semantic-conventions/build/esm/index.js

Downgrading back to @trigger.dev/[email protected] allows the build to complete successfully.

Reproduction repo

n/a

To reproduce

  1. Install @trigger.dev/[email protected]
  2. Create a task triggered in a Server Action
  3. Run pnpm build on [email protected] project

Additional information

I tried following suggestions in similar issues related to NextJS:

  • https://github.com/vercel/next.js/issues/60807
  • https://github.com/aws/aws-sdk-js-v3/issues/5488

Adding the following to next.config.js:

serverComponentsExternalPackages: [
      '@trigger.dev',
      '@trigger.dev/sdk',
      '@opentelemetry',
      '@opentelemetry/semantic-conventions'
 ]

Unfortunately to no avail.

rafalzawadzki avatar Dec 10 '24 20:12 rafalzawadzki

@rafalzawadzki Is this happening in a monorepo, or just a regular repo? Do you possibly have code that reproduces this? I'm unable to myself so far.

ericallam avatar Dec 13 '24 22:12 ericallam

Same here - any resolutions?

techjason avatar Dec 14 '24 14:12 techjason

@ericallam it's a standard Next repo (not monorepo, no turbo etc)

unfortunately can't provide the code

@techjason downgrading trigger was the workaround for now

rafalzawadzki avatar Dec 14 '24 15:12 rafalzawadzki

@rafalzawadzki I'm guessing in the "To reproduce" steps above you meant to say "Install @trigger.dev/sdk@latest"?

@techjason any chance you have a repo that can reproduce this? Could you provide any more details on your stack?

ericallam avatar Dec 14 '24 21:12 ericallam

+1 same issue here on the following version on a nextjs application

    "@trigger.dev/build": "3.3.7",
    "@trigger.dev/sdk": "3.3.7",
    "trigger.dev": "^3.0.12",

ming1in avatar Dec 16 '24 04:12 ming1in

@ming1in any chance you could share a minimal repo that reproduces this?

ericallam avatar Dec 16 '24 09:12 ericallam

Okay I've managed to reproduce this bug and here's what I found:

Between 14.0.0 and 14.2.7, there is a Next.js build issue that can occur in certain circumstances:

  1. Call a server action from a client component
  2. The server action imports a named function (for example, mockTriggerHelloWorldTask) from another file (let's call it triggerWrapper.ts)
  3. triggerWrapper.ts imports a Trigger.dev task defined in another file.
  4. The mockTriggerHelloWorldTask function does NOT make use of the Trigger.dev that was imported.

This will (for some reason) cause builds to fail with the above error (or one very similar). There are two fixes I've found so far for this:

  1. Upgrade to Next.js 14.2.8 or later
  2. OR, add this to your next config:
/** @type {import('next').NextConfig} */
const nextConfig = {
  experimental: {
    // Add this line to fix the "Cannot get final name for export" error
    // Alternatively, you can upgrade to Next.js 14.2.8 or later
    serverComponentsExternalPackages: ["@trigger.dev/sdk"],
  },
};

export default nextConfig;

@rafalzawadzki @techjason @rafalzawadzki

ericallam avatar Dec 16 '24 13:12 ericallam