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

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

Open
NickKelly1 opened this issue Oct 28, 2024 · 8 comments

Comments

@NickKelly1
Copy link

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/[email protected]/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/[email protected]/node_modules/pino/lib/caller.js:9:27)
    at pino (<cwd>/node_modules/.pnpm/[email protected]/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

Error.prepareStackTrace = noOpPrepareStackTrace

@mcollina
Copy link
Member

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
Copy link
Author

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

@NickKelly1
Copy link
Author

NickKelly1 commented Oct 31, 2024

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

> [email protected] test
> npm run lint && npm run transpile && tap --ts && jest test/jest && npm run test-types


> [email protected] 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

> [email protected] 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
Copy link
Member

running:

npm install
npm test

get everything done.

@NickKelly1
Copy link
Author

nick@marmot:~/development/tmp/80x/11/12$ git clone [email protected]: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 [email protected]: 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 [email protected]: Rimraf versions prior to v4 are no longer supported
npm warn deprecated @humanwhocodes/[email protected]: Use @eslint/config-array instead
npm warn deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm warn deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm warn deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm warn deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm warn deprecated @humanwhocodes/[email protected]: Use @eslint/object-schema instead
npm warn deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm warn deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm warn deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm warn deprecated [email protected]: 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 [email protected]: 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

> [email protected] test
> npm run lint && npm run transpile && tap --ts && jest test/jest && npm run test-types


> [email protected] lint
> eslint .


> [email protected] 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$

@mcollina
Copy link
Member

mcollina commented Nov 10, 2024

Which OS are you testing on? Everything works fine my machine and in CI.

@jsumners
Copy link
Member

https://asciinema.org/a/ohl58JUjtszTivRBZ2GoGXL6O

@NickKelly1
Copy link
Author

NickKelly1 commented Nov 12, 2024

I've pulled the latest main branch and it installs and tests now on node v20.18.0

Which OS are you testing on? Everything works fine my machine and in CI.

Linux 6.8.0-48-generic Ubuntu 22.04.5 LTS x86_64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants