-
Notifications
You must be signed in to change notification settings - Fork 879
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
Pino v7 shows "Cannot find module 'lib/worker.js' when bundling it with Rollup #1157
Comments
Thanks for the docs fix! |
Wait. It is not related to that fix! |
Ah! Sorry about this, I closed the wrong one. I'm not sure how bundling would work for this as we need to point to a separate file that will be loaded from disk by node, definitely from outside the bundle. |
Ref: #1104 |
This would need a specific import to be injected by the bundler. Something like: import worker from 'web-worker:./<path>/worker.js'; And in the rollup conf: import webWorkerLoader from 'rollup-plugin-web-worker-loader';
...
export default [
{
....
plugins: {
webWorkerloader({targetPlatform: 'browser', inline: true}),
}
] At the first glance it would chance the pino API to inject the reference right? |
likely so. Here is where we instatiate the actual worker object: https://github.com/pinojs/thread-stream/blob/79333e70994fb999300d0fcd73a3db12d69b8710/index.js#L39. Note that we should not use webworkers but worker_threads and target node. |
Is the idea of injecting the bundled worker within the // application code
pino.transport({
bundler: true
....
}) // pino
const w = require('lib/worker.js')
createWorker(stream,{ worker:w, evaluate:true} // thread-stream
function createWorker (stream, opts) {
const { filename, workerData, evaluate } = opts
let worker
if (evaluate === true) {
worker = new Worker (opts.worker.toString(),{
...opts.workerOpts,
eval:true,
workerData: {
dataBuf: stream._dataBuf,
stateBuf: stream._stateBuf,
workerData
}
})
} else {
const toExecute = join(__dirname, 'lib', 'worker.js')
worker = new Worker(toExecute, {
...opts.workerOpts,
workerData: {
filename: filename.indexOf('file://') === 0
? filename
: pathToFileURL(filename).href,
dataBuf: stream._dataBuf,
stateBuf: stream._stateBuf,
workerData
}
})
}
} Then the |
Note that the entrypoint is https://github.com/pinojs/thread-stream/blob/main/lib/worker.js, so we can already make it evaluate. |
This is also a problem with esbuild for console applications. |
@Everspace can you give esbuild-plugin-pino a try? |
@davipon sorry for getting back to you so late! By the time this happened I had already moved away from pino on the project I was spinning up, and haven't had the need to bundle a logger in an app since. I will let you know when I do however! |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Brief Description
Rollup
can't bundle theworker.js
of Pino v7 properly. There may be a Rollup plugin for bundling worker.js, but Pino seems like not compatible with this.Reproducible code and step
https://github.com/UnblockNeteaseMusic/server/blob/316766433de074ff94f120f515e058de63dae560/src/logger.js
The text was updated successfully, but these errors were encountered: