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

After building 'unable to determine transport target for "@axiomhq/pino"' due to "cjs" folder being deleted after build #1964

Open
AliD201 opened this issue May 4, 2024 · 1 comment

Comments

@AliD201
Copy link

AliD201 commented May 4, 2024

Hello !
thanks for the great package!

I have been trying to connect to axiom and send logs. while in development everything works fine.
but in deployment I keep receiving the follwoing error

unable to determine transport target for "@axiomhq/pino"
  at fixTarget (J:\...redecated...\.output\server\node_modules\pino\lib\transport.js:146:13)
  at Function.transport (J:\...redecated...\.output\server\node_modules\pino\lib\transport.js:116:22)

am using Nuxt3 with vite.
I did try to turn off treeshaking in nuxt.config.ts

  vite:{
    build:{
      rollupOptions:{
      // Exclude the package from tree shaking
      // external: ['@axiomhq']
      treeshake: false

      }
    }
  },

but still the same issue.

Here is my logger code:

import '@axiomhq/pino'
import pino from 'pino';

const logger = pino(
  { level: 'info',
    redact: {
      paths:["email","phone","mobile_number","customerMobile","TS_customer_mobile","TS_customer_email","TS_staff_member_mobile","TS_staff_member_email","user_mobile","user_email"],
      // remove: true
    }
  },
  pino.transport({
      target: '@axiomhq/pino',
      options: {
        dataset: useRuntimeConfig().axiomDataset,
        token: useRuntimeConfig().axiomToken,
        // dataset: process.env.AXIOM_DATASET,
        // token: process.env.AXIOM_TOKEN,
      },
  }
  ),
);
export {logger}

Note: it works just fine with pino-pretty. but am not sure what is happening in the building step.

i spent my whole day playing around .. and I have no clue... what is happening on the build step

Debugging the production version using this modification :

  function fixTarget (origin) {
    origin = bundlerOverrides[origin] || origin

    if (isAbsolute(origin) || origin.indexOf('file://') === 0) {
      return origin
    }

    if (origin === 'pino/file') {
      return join(__dirname, '..', 'file.js')
    }

    let fixTarget

    for (const filePath of callers) {
      try {
        const context = filePath === 'node:repl'
          ? process.cwd() + sep
          : filePath
        throw new Error(createRequire(context).resolve(origin))
        console.log(createRequire(context).resolve(origin))
        fixTarget = createRequire(context).resolve(origin)
        break
      } catch (err) {
        // Silent catch
        throw new Error(err)
        continue
      }
    }

    if (!fixTarget) {
      throw new Error(`unable to determine transport target for "${origin}"`)
    }

    return fixTarget
  }
}

shows that the @axiomhq\pino\dist\cjs\index.cjs is what it tries to use.

though in vite .cjs is depreciated and it should use .mjs
also in the build output the cjs folder is deleted and doesn't exists, which causes this error.

@mcollina
Copy link
Member

mcollina commented May 6, 2024

Thanks for reporting!

Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.

These bundling issues are quite tricky, so if you would like to also send a PR... that would be amazing.

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

No branches or pull requests

2 participants