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

Cannot assign to read only property 'name' of function 'function Constructor #4

Open
erictraub opened this issue Aug 24, 2017 · 3 comments

Comments

@erictraub
Copy link

I started getting this error recently. I believe that it is from the library createerror that is a dependency. How can I fix it?

TypeError: Cannot assign to read only property 'name' of function 'function Constructor(messageOrOptionsOrError, preserveError) {
            if (preprocess) {
                va...<omitted>... }'
    at createError (/home/dev/web-node-server/server/node_modules/createerror/lib/createError.js:125:13)
    at Object.<anonymous> (/home/dev/web-node-server/server/node_modules/httperrors/lib/HttpError.js:48:34)
    at Module._compile (module.js:571:32)
    at loader (/home/dev/web-node-server/server/node_modules/babel-register/lib/node.js:144:5)
    at Object.require.extensions.(anonymous function) [as .js] (/home/dev/web-node-server/server/node_modules/babel-register/lib/node.js:154:7)
papandreou added a commit to One-com/node-createerror that referenced this issue Aug 24, 2017
@papandreou
Copy link
Collaborator

Thanks for getting in touch!

I couldn't reproduce the problem myself (it might depend on a specific version of node or something else), but I vaguely remember a similar problem where using Object.defineProperty to override a function name worked fine, as opposed to just changing fn.name.

I've attempted a fix here: One-com/node-createerror@f6b09ec

It's included in httperrors 2.3.0 -- could you try that and see if it helped?

@gustavnikolaj
Copy link
Collaborator

Closing this issue assuming that the above fix by @papandreou adressed the issue. Let us know if that's not the case!

@alexjeffburke
Copy link

We are using createerror in the browser and have just lived through some consequences of this that I think should be documented. Please consider the commentary below"in the browser".

Without this change, it appears that you get the error mentioned by the original reporter if you happen to bundle this code in strict mode - unfortunately at least rollup will add the "use strict" pragma by default when doing an ES6 module to UMD build.

The Object.defineProperty fix is arguably worse though - it breaks hard on Safari version 9 (meaning on iOS 9 and macOS 10.9-10.11) causing it to throw "TypeError: Attempting to change value of a readonly property.". If this version is required by httpErrors I'd assume it has also now inherited this problem.

@alexjeffburke alexjeffburke reopened this Jul 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants