pinojs / pino

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

--frozen-intrinsics: Cannot assign to read only property 'prepareStackTrace' of function 'function Error() { [native code] }' #2071

Open NickKelly1 opened 1 week ago

NickKelly1 commented 1 week ago

When the NodeJS process runs with --frozen-intrinsics, creating a pino logger throws an error.

> node --env-file ./.env --enable-source-maps --disable-proto=throw --disallow-code-generation-from-strings --frozen-intrinsics ./build/main.js

(node:1764737) ExperimentalWarning: Frozen intristics is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
<cwd>/node_modules/.pnpm/pino@9.5.0/node_modules/pino/lib/caller.js:9
  Error.prepareStackTrace = noOpPrepareStackTrace
                          ^

TypeError <Object <Object <[Object: null prototype] {}>>>: Cannot assign to read only property 'prepareStackTrace' of function 'function Error() { [native code] }'
    at getCallers (<cwd>/node_modules/.pnpm/pino@9.5.0/node_modules/pino/lib/caller.js:9:27)
    at pino (<cwd>/node_modules/.pnpm/pino@9.5.0/node_modules/pino/pino.js:90:48)
    at server (<cwd>/src/commands/server.ts:8:17)
    at main (<cwd>/src/main.ts:58:8)
    at <anonymous> (<cwd>/src/main.ts:63:26)
    at ModuleJob.run (node:internal/modules/esm/module_job:268:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:543:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:116:5)

Node.js v23.1.0
ELIFECYCLE Command failed with exit code 1.
[nodemon] app crashed - waiting for file changes before starting...

Due to this line

https://github.com/pinojs/pino/blob/231adffeccd71f26627a43260c09bfb61a98fcaa/lib/caller.js#L9

mcollina commented 5 days ago

Thanks for reporting! Now that Node.js has util.getCallSite(), I think we can rely on that instead of patching Error to achieve this if that new function is available. Would you like to send a Pull Request to address this? Remember to add unit tests.

NickKelly1 commented 5 days ago

Sure thing, I'll create a a PR for it.

NickKelly1 commented 4 days ago

I'm not sure how to build or test the project after looking in the README.md and CONTRIBUTING.md. I installed dependencies with npm install. npm run test is failing for me due to linting errors and npm run transpile && tap --ts && jest test/jest && npm run test-types is also failing due to typescript errors. How can I proceed?

NodeJS version 22.11.0 git main 231adff build(deps-dev): bump @yao-pkg/pkg from 5.15.0 to 6.0.0 (#2070)

npm run test

> pino@9.5.0 test
> npm run lint && npm run transpile && tap --ts && jest test/jest && npm run test-types

> pino@9.5.0 lint
> eslint .

<...>/pino/test/fixtures/ts/to-file-transport.js
   1:1    error  Strings must use singlequote                                   quotes
   1:13   error  Extra semicolon                                                semi
   3:1    error  Expected indentation of 2 spaces but found 4                   indent
   3:19   error  Missing space before function parentheses                      space-before-function-paren
   3:106  error  Extra semicolon                                                semi
   3:110  error  Extra semicolon                                                semi
   4:1    error  Expected indentation of 2 spaces but found 4                   indent
   5:1    error  Expected indentation of 4 spaces but found 8                   indent
   5:27   error  Missing space before function parentheses                      space-before-function-paren
   5:70   error  Extra semicolon                                                semi
   5:95   error  Extra semicolon                                                semi
   6:1    error  Expected indentation of 4 spaces but found 8                   indent
   6:26   error  Missing space before function parentheses                      space-before-function-paren
   6:57   error  ["throw"] is better written in dot notation                    dot-notation
   6:57   error  Strings must use singlequote                                   quotes
   6:73   error  Extra semicolon                                                semi

# ...
npm run transpile && npx tap --ts && jest test/jest && npm run test-types

> pino@9.5.0 transpile
> node ./test/fixtures/ts/transpile.cjs

<...>/pino/node_modules/execa/lib/error.js:60
                error = new Error(message);
                        ^

Error: Command failed with exit code 2: tsc --target es5 --module commonjs to-file-transport.ts
../../../node_modules/@types/node/events.d.ts(144,18): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher.
    at makeError (<...>/pino/node_modules/execa/lib/error.js:60:11)
    at handlePromise (<...>/pino/node_modules/execa/index.js:118:26)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async transpile (<...>/pino/test/fixtures/ts/transpile.cjs:26:9) {
  shortMessage: 'Command failed with exit code 2: tsc --target es5 --module commonjs to-file-transport.ts',
  command: 'tsc --target es5 --module commonjs to-file-transport.ts',
  escapedCommand: 'tsc --target es5 --module commonjs to-file-transport.ts',
  exitCode: 2,
  signal: undefined,
  signalDescription: undefined,
  stdout: '../../../node_modules/@types/node/events.d.ts(144,18): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher.',
  stderr: '',
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}

Node.js v22.11.0
mcollina commented 4 days ago

running:

npm install
npm test

get everything done.

NickKelly1 commented 4 days ago
nick@marmot:~/development/tmp/80x/11/12$ git clone git@github.com:pinojs/pino.git
Cloning into 'pino'...
remote: Enumerating objects: 8967, done.
remote: Counting objects: 100% (2410/2410), done.
remote: Compressing objects: 100% (401/401), done.
remote: Total 8967 (delta 2177), reused 2182 (delta 2005), pack-reused 6557 (from 1)
Receiving objects: 100% (8967/8967), 3.01 MiB | 7.23 MiB/s, done.
Resolving deltas: 100% (6242/6242), done.
nick@marmot:~/development/tmp/80x/11/12$ cd pino
nick@marmot:~/development/tmp/80x/11/12/pino$ node -v
v20.18.0
nick@marmot:~/development/tmp/80x/11/12/pino$ git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean
nick@marmot:~/development/tmp/80x/11/12/pino$ git branch -v
* main 231adff build(deps-dev): bump @yao-pkg/pkg from 5.15.0 to 6.0.0 (#2070)
nick@marmot:~/development/tmp/80x/11/12/pino$ npm install
npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated rimraf@2.4.5: Rimraf versions prior to v4 are no longer supported
npm warn deprecated @humanwhocodes/config-array@0.13.0: Use @eslint/config-array instead
npm warn deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
npm warn deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
npm warn deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
npm warn deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
npm warn deprecated @humanwhocodes/object-schema@2.0.3: Use @eslint/object-schema instead
npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm warn deprecated glob@6.0.4: Glob versions prior to v9 are no longer supported
npm warn deprecated glob@5.0.15: Glob versions prior to v9 are no longer supported
npm warn deprecated docsify-server-renderer@4.13.1: docsify-server-renderer 4.x and below is no longer supported while we investigate the future of SSR and SSG for Docsify
npm warn deprecated eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options.

added 1443 packages, and audited 1607 packages in 8s

212 packages are looking for funding
  run `npm fund` for details

9 vulnerabilities (7 moderate, 2 high)

To address issues that do not require attention, run:
  npm audit fix

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.
nick@marmot:~/development/tmp/80x/11/12/pino$ npm test

> pino@9.5.0 test
> npm run lint && npm run transpile && tap --ts && jest test/jest && npm run test-types

> pino@9.5.0 lint
> eslint .

> pino@9.5.0 transpile
> node ./test/fixtures/ts/transpile.cjs

/home/nick/development/tmp/80x/11/12/pino/node_modules/execa/lib/error.js:60
                error = new Error(message);
                        ^

Error: Command failed with exit code 2: tsc --target es5 --module commonjs to-file-transport.ts
../../../node_modules/@types/node/events.d.ts(144,18): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher.
    at makeError (/home/nick/development/tmp/80x/11/12/pino/node_modules/execa/lib/error.js:60:11)
    at handlePromise (/home/nick/development/tmp/80x/11/12/pino/node_modules/execa/index.js:118:26)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async transpile (/home/nick/development/tmp/80x/11/12/pino/test/fixtures/ts/transpile.cjs:26:9) {
  shortMessage: 'Command failed with exit code 2: tsc --target es5 --module commonjs to-file-transport.ts',
  command: 'tsc --target es5 --module commonjs to-file-transport.ts',
  escapedCommand: 'tsc --target es5 --module commonjs to-file-transport.ts',
  exitCode: 2,
  signal: undefined,
  signalDescription: undefined,
  stdout: '../../../node_modules/@types/node/events.d.ts(144,18): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher.',
  stderr: '',
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}

Node.js v20.18.0
nick@marmot:~/development/tmp/80x/11/12/pino$