pinojs / pino

🌲 super fast, all natural json logger
http://getpino.io
MIT License
14.21k stars 875 forks source link

TypeError [ERR_INVALID_ARG_VALUE]: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received undefined #1255

Closed shahinghasemi closed 2 years ago

shahinghasemi commented 2 years ago

Hi, this is the code below:

  const transport = pino.transport({ target: 'pino-pretty' });
  const logger = pino(transport);

and this is the error that throws when webpack command executes:

TypeError [ERR_INVALID_ARG_VALUE]: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received undefined
    at __node_internal_captureLargerStackTrace (node:internal/errors:456:5)
    at __node_internal_addCodeToName (node:internal/errors:191:9)
    at new NodeError (node:internal/errors:363:5)
    at createRequire (node:internal/modules/cjs/loader:1203:11)
    at Function.transport (/home/shahin/codes/lernito-exam/backend/node_modules/pino/lib/transport.js:84:25)
    at __WEBPACK_DEFAULT_EXPORT__ (webpack-internal:///./src/logger/makeLogger.ts:19:60)
    at eval (webpack-internal:///./src/logger/index.ts:16:68)
    at Object../src/logger/index.ts (webpack://backend/node_modules/@iin/porspack/src/adaptors/QuestionAdaptor.ts?2c19:8:1)
    at null.__webpack_require__ (webpack://backend/node_modules/@iin/porspack/src/adaptors/QuestionAdaptor.ts?2c19:8:1)
    at eval (webpack-internal:///./src/setupEnv.ts:2:65)
    at Object../src/setupEnv.ts (webpack://backend/node_modules/@iin/porspack/src/adaptors/QuestionAdaptor.ts?2c19:8:1)
    at null.__webpack_require__ (webpack://backend/node_modules/@iin/porspack/src/adaptors/QuestionAdaptor.ts?2c19:8:1)
    at eval (webpack-internal:///./src/main.ts:2:67)
    at Object../src/main.ts (webpack://backend/node_modules/@iin/porspack/src/adaptors/QuestionAdaptor.ts?2c19:8:1)
    at null.__webpack_require__ (webpack://backend/node_modules/@iin/porspack/src/adaptors/QuestionAdaptor.ts?2c19:8:1)
    at null.<anonymous> (webpack://backend/node_modules/@iin/porspack/src/adaptors/QuestionAdaptor.ts?2c19:8:1)
    at Object.<anonymous> (webpack://backend/node_modules/@iin/porspack/src/adaptors/QuestionAdaptor.ts?2c19:8:1)
    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:823:16)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'ERR_INVALID_ARG_VALUE'
}

If you want any further code/description let me know.

Thanks in advance.

mcollina commented 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?

shahinghasemi commented 2 years ago

@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)
mcollina commented 2 years ago

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!

shahinghasemi commented 2 years ago

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'
}
mcollina commented 2 years ago

Please provide a full example to reproduce your problem, ideally in a repository we can easily clone.

shahinghasemi commented 2 years ago

Hello @mcollina , please clone this: https://github.com/shahinghasemi/pino-transport-bug

ja-bravo commented 2 years ago

I can reproduce the error with the repository above, I'm going to investigate

ja-bravo commented 2 years ago

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

gdorsi commented 2 years ago

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!')
simoneb commented 2 years ago

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

shahinghasemi commented 2 years ago

@mcollina Thank you for fixing the issue. When the new release with this changes would be? is there any milestone to check?

github-actions[bot] commented 2 years ago

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.