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

not supported by esbuild-plugin-pino #105

Closed
ben-reitz opened this issue Jul 24, 2024 · 2 comments · Fixed by #106
Closed

not supported by esbuild-plugin-pino #105

ben-reitz opened this issue Jul 24, 2024 · 2 comments · Fixed by #106

Comments

@ben-reitz
Copy link
Contributor

Raised an issue on esbuild-plugin-pino too (wd-David/esbuild-plugin-pino#173) as I'm not sure where the issues lies. I've looked into it a bit and I think this is where the issue lies:


I'm getting the following error when running my app:

"Error: Cannot find module '/var/task/dist/lib/TcpConnection'",
        "Require stack:",
        "- /var/task/dist/pino-socket.js",
        "    at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)",
        "    at Module._load (node:internal/modules/cjs/loader:986:27)",
        "    at Module.require (node:internal/modules/cjs/loader:1233:19)",
        "    at require (node:internal/modules/helpers:179:18)",
        "    at Object.<anonymous> (/var/task/node_modules/pino-socket/psock.js:5:30)",
        "    at Module._compile (node:internal/modules/cjs/loader:1358:14)",
        "    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)",
        "    at Module.load (node:internal/modules/cjs/loader:1208:32)",
        "    at Module._load (node:internal/modules/cjs/loader:1024:12)",
        "    at cjsLoader (node:internal/modules/esm/translators:348:17)"

This is because pino-socket has the following line in its main entrypoint:

const tcpConnectionFactory = require(path.join(__dirname, 'lib', 'TcpConnection'))`

which is being transpiled by esbuild to

sf=require(Ie.join(__dirname,"lib","TcpConnection"))

which doesn't work as only a single file pino-socket.js is being created for it.

Is there a way around this or is there an issue with my config?

pino config:
const logger = pino({
    level: 'info',
    transport: {
        pipeline: [
            {
                target: 'pino-syslog',
                options: {
                    appname: process.env.AWS_LAMBDA_FUNCTION_NAME,
                    newline: true,
                },
            },
            {
                target: 'pino-socket',
                options: {
                    host: process.env.LOG_COLLECTOR_HOST,
                    port: process.env.LOG_COLLECTOR_PORT,
                    mode: 'tcp',
                    secure: true,
                },
            },
        ],
    },
});
build:
await esbuild.build({
    entryPoints: [{ in: 'src/server/lambdaHandler.ts', out: 'server' }],
    bundle: true,
    platform: 'node',
    target: 'node20',
    outdir: 'dist',
    minify: true,
    sourcemap: true,
    plugins: [esbuildPluginPino({ transports: ['pino-pretty', 'pino-syslog', 'pino-socket'] })],
    logLevel: 'info',
});
@mcollina
Copy link
Member

I think you can send a PR here that removes that path.join(). It's not necessary.

@ben-reitz
Copy link
Contributor Author

Thanks @mcollina - I've raised #106

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

Successfully merging a pull request may close this issue.

2 participants