-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
TypeError: Cannot add property source
, object is not extensible
#57030
Comments
/cc @joyeecheung |
It seems both the async version and the sync version of the example are incorrect:
|
Also both versions could not produce valid module types, since the documentation does not mention adding a |
Actually I remember this was one the reasons I left https://github.com/nodejs/node/blob/main/doc/api/module.md?plain=1#L1348-L1350 because it seems the examples have been broken for a while due to lack of testing.... |
@joyeecheung I believe the async hooks version handles default context properly and sync does not. Consider following minimal example:
Now running the async hook finishes without any errors:
In contrast if I try to run the sync hook I get an error:
I would assume that both would have the same results. Why is that the sync version throws? 🤔 |
According to discussions in #57037 the sync hooks are currently making the context parameter mandatory (as a result an internal context is created in the absence of that, which is frozen it seems). Until we fix it internally, you could make it work by always passing the context parameter to |
The loader hooks examples have been broken for a while: 1. The nextLoad() hook cannot be used on a .coffee file that ends up going to the default load step without an explict format, which would cause a ERR_UNKNOWN_FILE_EXTENSION. Mention adding a package.json with a type field to work around it in the example. 2. Pass the context parameter to the nextLoad() invocation and document that context.format is mandatory when module type is not explicitly inferrable from the module. 3. Correct the getPackageType() implementation which returns false instead of undefined in the absence of an explict format, which is not a valid type for format. PR-URL: #57037 Refs: #57030 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
The loader hooks examples have been broken for a while: 1. The nextLoad() hook cannot be used on a .coffee file that ends up going to the default load step without an explict format, which would cause a ERR_UNKNOWN_FILE_EXTENSION. Mention adding a package.json with a type field to work around it in the example. 2. Pass the context parameter to the nextLoad() invocation and document that context.format is mandatory when module type is not explicitly inferrable from the module. 3. Correct the getPackageType() implementation which returns false instead of undefined in the absence of an explict format, which is not a valid type for format. PR-URL: #57037 Refs: #57030 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This aligns the behavior of synchronous hooks with asynchronous hooks by allowing omission of the context parameter in the invocation of next hooks. The contexts are merged along the chain. PR-URL: nodejs#57056 Fixes: nodejs#57030 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
The loader hooks examples have been broken for a while: 1. The nextLoad() hook cannot be used on a .coffee file that ends up going to the default load step without an explict format, which would cause a ERR_UNKNOWN_FILE_EXTENSION. Mention adding a package.json with a type field to work around it in the example. 2. Pass the context parameter to the nextLoad() invocation and document that context.format is mandatory when module type is not explicitly inferrable from the module. 3. Correct the getPackageType() implementation which returns false instead of undefined in the absence of an explict format, which is not a valid type for format. PR-URL: nodejs#57037 Refs: nodejs#57030 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This aligns the behavior of synchronous hooks with asynchronous hooks by allowing omission of the context parameter in the invocation of next hooks. The contexts are merged along the chain. PR-URL: nodejs#57056 Fixes: nodejs#57030 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This aligns the behavior of synchronous hooks with asynchronous hooks by allowing omission of the context parameter in the invocation of next hooks. The contexts are merged along the chain. PR-URL: #57056 Fixes: #57030 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Version
v23.7.0
Platform
Subsystem
No response
What steps will reproduce the bug?
To reproduce the issue try running the synchronous version of the transpilation example.
How often does it reproduce? Is there a required condition?
100%
What is the expected behavior? Why is that the expected behavior?
I would expect the code from the API docs to run without any errors.
What do you see instead?
Additional information
No response
The text was updated successfully, but these errors were encountered: