Closed shahinghasemi closed 2 years ago
Have you followed the guide at https://github.com/pinojs/pino/blob/master/docs/bundling.md? If so could you upload a full repository with a complete way to reproduce?
@mcollina Thanks for the reply. I just followed them and the previous error is now gone! however I encountered a new one. this is the code to reproduce:
webpack.config.js
:
const {PinoWebpackPlugin} = require('pino-webpack-plugin')
module.exports = {
entry: './pino/logger.js',
mode: 'development',
plugins: [
new PinoWebpackPlugin({ transports: ['pino-pretty'] })
]
}
./pino/logger.js
:
const pino = require('pino');
const transport = pino.transport({target: 'pino-pretty'})
const logger = pino(transport)
logger.info('done!')
package.json
:
{
"scripts": {
"webpack": "webpack"
},
"dependencies": {
"get-caller-file": "^2.0.5",
"pino": "^7.5.1",
"pino-abstract-transport": "^0.5.0",
"pino-pretty": "^7.2.0",
"pino-webpack-plugin": "^1.1.0",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1",
"webpack-node-externals": "^3.0.0"
}
}
First I executed npm run webpack
then the bundles are generated inside dist
directory: main.js
, pino-file.js
, pino-pipeline-worker.js
, pino-worker.js
.
Finally I execute node dist/main.js
which gives me this error:
const transport = pino.transport({target: 'pino-pretty'})
^
TypeError: pino.transport is not a function
at eval (webpack://test_station/./pino/logger.js?:2:24)
at Object../pino/logger.js (/home/shahin/codes/test_station/dist/main.js:43:1)
at __webpack_require__ (/home/shahin/codes/test_station/dist/main.js:78:41)
at /home/shahin/codes/test_station/dist/main.js:89:37
at Object.<anonymous> (/home/shahin/codes/test_station/dist/main.js:91:12)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
You are missing a target: 'node'
in your webpack config.
Would you mind to verify everything works and send a PR to our docs to specify this is needed? Thx!
Sure but the error still exists even adding target:node
:
node:internal/modules/cjs/loader:1203
throw new ERR_INVALID_ARG_VALUE('filename', filename, createRequireError);
^
TypeError [ERR_INVALID_ARG_VALUE]: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received undefined
at new NodeError (node:internal/errors:363:5)
at createRequire (node:internal/modules/cjs/loader:1203:11)
at Function.transport (webpack://test_station/./node_modules/pino/lib/transport.js?:83:25)
at eval (webpack://test_station/./pino/logger.js?:2:24)
at Object../pino/logger.js (/home/shahin/codes/test_station/dist/main.js:558:1)
at __webpack_require__ (/home/shahin/codes/test_station/dist/main.js:978:41)
at /home/shahin/codes/test_station/dist/main.js:989:37
at Object.<anonymous> (/home/shahin/codes/test_station/dist/main.js:991:12)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10) {
code: 'ERR_INVALID_ARG_VALUE'
}
Please provide a full example to reproduce your problem, ideally in a repository we can easily clone.
Hello @mcollina , please clone this: https://github.com/shahinghasemi/pino-transport-bug
I can reproduce the error with the repository above, I'm going to investigate
I could not find exactly what the error is but I think it's actually related to pino-webpack-plugin
and eval.
You can get the repo linked above by changing the webpack config to either match the one used in their tests i.e: mode: production
, optimization: { minimize: false }
Or using any devtool value that does not use eval (reference)
I researched a bit but I have no experience with webpack plugins so didn't get anywhere, maybe the devtool workaround works for you @shahinghasemi
Hello!
I've added a test case on pino-webpack-plugin and found that merging this would solve the issue.
As a quick workaround you could also try to add caller: __filename
to the pino transport options:
const pino = require('pino');
- const transport = pino.transport({target: 'pino-pretty'})
+ const transport = pino.transport({target: 'pino-pretty',caller: __filename})
const logger = pino(transport)
logger.info('done!')
I guess @ShogunPanda was probably aware of this issue then. Good that we have that one issue. So once that is in this issue is probably solved as well
@mcollina Thank you for fixing the issue. When the new release with this changes would be? is there any milestone to check?
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.
Hi, this is the code below:
and this is the error that throws when
webpack
command executes:If you want any further code/description let me know.
Thanks in advance.