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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Cannot assign to read only property 'stackTraceLimit' #15625

Closed
1 task
loynoir opened this issue May 12, 2023 · 10 comments 路 Fixed by #15626
Closed
1 task

[Bug]: Cannot assign to read only property 'stackTraceLimit' #15625

loynoir opened this issue May 12, 2023 · 10 comments 路 Fixed by #15626
Assignees
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: core

Comments

@loynoir
Copy link

loynoir commented May 12, 2023

馃捇

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

import { parse } from "@babel/core";
console.log(parse("").type);

Configuration file name

No response

Configuration

No response

Current and expected behavior

$ node reproduce.mjs
File
$  node --frozen-intrinsics reproduce.mjs 
(node:602173) ExperimentalWarning: The --frozen-intrinsics flag is experimental
(Use `node --trace-warnings ...` to show where the warning was created)
/path/to/node_modules/@babel/core/lib/errors/rewrite-stack-trace.js:65
  Error.stackTraceLimit && (Error.stackTraceLimit = Math.max(Error.stackTraceLimit, MIN_STACK_TRACE_LIMIT));
                                                  ^

TypeError <Object <Object <[Object: null prototype] {}>>>: Cannot assign to read only property 'stackTraceLimit' of function 'function Error() { [native code] }'
    at setupPrepareStackTrace (/path/to/node_modules/@babel/core/lib/errors/rewrite-stack-trace.js:65:51)
    at stopHiding - secret - don't use this - v1 (/path/to/node_modules/@babel/core/lib/errors/rewrite-stack-trace.js:45:5)
    at parse (/path/to/node_modules/@babel/core/lib/parse.js:34:76)
    at file:///path/to/reproduce.mjs:2:13
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Node.js v18.15.0

Environment

"@babel/core": "^7.21.8"

node v18.15.0

Possible solution

diff --git a/node_modules/@babel/core/lib/errors/rewrite-stack-trace.js b/node_modules/@babel/core/lib/errors/rewrite-stack-trace.js
index 9b6ce01..0757ad6 100644
--- a/node_modules/@babel/core/lib/errors/rewrite-stack-trace.js
+++ b/node_modules/@babel/core/lib/errors/rewrite-stack-trace.js
@@ -62,6 +62,7 @@ function setupPrepareStackTrace() {
     prepareStackTrace = defaultPrepareStackTrace
   } = Error;
   const MIN_STACK_TRACE_LIMIT = 50;
+  try {
   Error.stackTraceLimit && (Error.stackTraceLimit = Math.max(Error.stackTraceLimit, MIN_STACK_TRACE_LIMIT));
   Error.prepareStackTrace = function stackTraceRewriter(err, trace) {
     let newTrace = [];
@@ -87,6 +88,7 @@ function setupPrepareStackTrace() {
     }
     return prepareStackTrace(err, newTrace);
   };
+  } catch {}
 }
 function defaultPrepareStackTrace(err, trace) {
   if (trace.length === 0) return ErrorToString(err);
$ node --frozen-intrinsics reproduce.mjs
(node:604212) ExperimentalWarning: The --frozen-intrinsics flag is experimental
(Use `node --trace-warnings ...` to show where the warning was created)
File

Additional context

No response

@babel-bot
Copy link
Collaborator

Hey @loynoir! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

@nicolo-ribaudo
Copy link
Member

Ideally we should also have a test with --frozen-intrinsics, I'd like Babel to work in that mode.

@liuxingbaoyu
Copy link
Member

image
I opened a PR #15626.
This problem seems to only exist in some versions.

@liuxingbaoyu
Copy link
Member

image
Maybe nodejs changed behavior in newer versions?

@loynoir
Copy link
Author

loynoir commented May 13, 2023

I'm on v18.15.0. What version are you using?

@liuxingbaoyu
Copy link
Member

v19.8.1
Don't worry, even though I can't reproduce it, I still think the problem exists.
Because there is a related PR nodejs/node#38215 in nodejs.

@loynoir
Copy link
Author

loynoir commented May 13, 2023

@liuxingbaoyu

馃 Are you using nodejs wrapper that does not accept CLI flags?


$ img=docker.io/library/node:19.8.1@sha256:1fab548e95c779df229e4b50d8d20e222597bda15aeece508098c5ba7723302e                                          
$ docker run --rm -it -v "$PWD":/app -w /app "$img" node --frozen-intrinsics ./reproduce.mjs               
(node:1) ExperimentalWarning: The --frozen-intrinsics flag is experimental
(Use `node --trace-warnings ...` to show where the warning was created)
/app/node_modules/@babel/core/lib/errors/rewrite-stack-trace.js:65
  Error.stackTraceLimit && (Error.stackTraceLimit = Math.max(Error.stackTraceLimit, MIN_STACK_TRACE_LIMIT));
                                                  ^

TypeError <Object <Object <[Object: null prototype] {}>>>: Cannot assign to read only property 'stackTraceLimit' of function 'function Error() { [native code] }'
    at setupPrepareStackTrace (/app/node_modules/@babel/core/lib/errors/rewrite-stack-trace.js:65:51)
    at stopHiding - secret - don't use this - v1 (/app/node_modules/@babel/core/lib/errors/rewrite-stack-trace.js:45:5)
    at parse (/app/node_modules/@babel/core/lib/parse.js:34:76)
    at file:///app/reproduce.mjs:2:13
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)

Node.js v19.8.1

$ img=docker.io/library/node:20@sha256:0efc3ef3fea2822c9d16da084c40181ed7f74b6f45141100580f9887ccc8e9a
$ docker run --rm -it -v "$PWD":/app -w /app "$img" node --frozen-intrinsics ./reproduce.mjs           
(node:1) ExperimentalWarning: The --frozen-intrinsics flag is experimental
(Use `node --trace-warnings ...` to show where the warning was created)
/app/node_modules/@babel/core/lib/errors/rewrite-stack-trace.js:65
  Error.stackTraceLimit && (Error.stackTraceLimit = Math.max(Error.stackTraceLimit, MIN_STACK_TRACE_LIMIT));
                                                  ^

TypeError <Object <Object <[Object: null prototype] {}>>>: Cannot assign to read only property 'stackTraceLimit' of function 'function Error() { [native code] }'
    at setupPrepareStackTrace (/app/node_modules/@babel/core/lib/errors/rewrite-stack-trace.js:65:51)
    at stopHiding - secret - don't use this - v1 (/app/node_modules/@babel/core/lib/errors/rewrite-stack-trace.js:45:5)
    at parse (/app/node_modules/@babel/core/lib/parse.js:34:76)
    at file:///app/reproduce.mjs:2:13
    at ModuleJob.run (node:internal/modules/esm/module_job:192:25)

Node.js v20.1.0

@liuxingbaoyu
Copy link
Member

image
It seems not.
Obviously the flag is working.

@liuxingbaoyu
Copy link
Member

Strangely, when I test inside babel, it throws this error.馃槙

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented May 13, 2023

Assignment to read-only properties only throws in strict mode!

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Sep 13, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: core
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants