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

I can't load this transport in Vercel, neither through relative nor through absolute path #10

Open
nemanjam opened this issue Jun 20, 2023 · 0 comments

Comments

@nemanjam
Copy link

In the Readme.md you load transport file via relative path, with Next.js this breaks for me in both local dev environment and Vercel prod:

const logger = pino(
  pino.transport({
    targets: [
      { level: 'debug', target: '../lib/logger.mjs', options }
    ]
  })
)

Absolute path works for me locally but absolute paths are problematic in Vercel and I couldn't get to work there. Here is one such hack to force Vercel to include js file in bundle and reference it through absolute path, but this doesn't work for me:

vercel/next.js#32236 (reply in thread)

Here is my code:

import path from 'node';
import { LoggerOptions, TransportTargetOptions, pino } from 'pino';


const transportAbsolutePath = path.join(process.cwd(), '/lib/transport.mjs');


const targets: TransportTargetOptions[] = [
  { target: 'pino-pretty', level: 'info', options: { colorize: true } },
];

// breaks both locally and in Vercel
const transportRelativePath = '../transport.mjs';

// breaks in Vercel, can't find file on that path
targets.push({ target: transportAbsolutePath, level: 'info', options: {} });


const destination = pino.transport({ targets });

const pinoOptions: LoggerOptions = {
  enabled: true,
  timestamp: pino.stdTimeFunctions.isoTime,
};

export const logger = pino(pinoOptions, destination);

transport.mjs

import { createTransport } from 'pino-slack-transport';

export default createTransport;

I have tried to use CopyWebpackPlugin to include transport.js file in the bundle and reference it by absolute path but again it works locally and breaks in Vercel.

next.config.js

const CopyWebpackPlugin = require('copy-webpack-plugin');

const nextConfig = {
  reactStrictMode: true,
  webpack(config, options) {

    if (options.isServer) {

      config.plugins.push(
        new CopyWebpackPlugin({
          patterns: [
            {
              from: path.join(__dirname, 'lib/logger/transport.mjs'),
              to: path.join(__dirname, '.next/server'),
            },
          ],
        })
      );
    }

    return config;
  },
};

I have also tried to load transport through PinoWebpackPlugin and not through code but it doesn't even compile in dev as soon as I import it.

next.config.js

// it breaks build on this import
const { PinoWebpackPlugin } = require('pino-webpack-plugin');

const nextConfig = {
  reactStrictMode: true,
  webpack(config, options) {

    config.plugins.push(
      new PinoWebpackPlugin({
        transports: [
          'pino-pretty',
          path.join(__dirname, 'lib/logger/transport.mjs'),
        ],
      })
    );

    return config;
  },
};

Do you know some way I can load this transport in Vercel in Next.js app?

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

1 participant