modules: deprecate module.parent - #32217
Conversation
❌I'm opposedMy dissent is voiced in a comment to the related issue. |
devsnek
left a comment
There was a problem hiding this comment.
even before esm existed this should've been deprecated
e1f6f47 to
3dbaf67
Compare
|
While we are here, can we update https://github.com/nodejs/node/blob/master/doc/api/modules.md#moduleparent to state that the value may be |
addaleax
left a comment
There was a problem hiding this comment.
I’m -1 on a runtime deprecation just because a feature won’t always work as expected.
This only starts to break when people are moving code over to ESM. When it does break, it will most likely break in a way that’s easily noticed. I don’t think an extra runtime deprecation would be helpful.
|
@addaleax do you feel comfortable with docs deprecation? |
|
@addaleax it breaks when people are using ESM or REPL, there is a better alternative that always works, and it seems there is no actual use-case for this feature. Anyway, would you find it acceptable if the warning is displayed only when |
3dbaf67 to
b76b302
Compare
b76b302 to
d9651f0
Compare
@addaleax I don't think that's a fair assumption: when I did encounter the issue, I was porting a library of mine to ESM, and it was not obvious what what did go wrong. One of the dependency is using a check on I know this is just anecdotal evidence, yet I am convinced a runtime warning is needed; hopefully my user story shows how Node.js can benefit from a runtime deprecation. To avoid leaking warnings to library users, I have changed the algorithm to warn only when
I have also added a code snippet in the deprecation note to tell users how to get the current module's parents to address @DerekNonGeneric's concern. |
left a comment
There was a problem hiding this comment.
I’ll remove my objection since the PR now warns in different situations, but I still think that this is not a good idea, tbh.
If the problem is that module.parent == null happens unexpectedly when importing from ESM, I would try to fix that by returning a fake object for module.parent in that situation – it doesn’t really have to be a full Module, just something as close to it as that makes sense.
I also still think that a full runtime deprecation is overkill, and I would feel more comfortable introducing this only for --pending-deprecation at first – especially as we generally aim to documentation-deprecate features before runtime-deprecating them.
commented
Jul 23, 2020
|
@papb yes, we have talked about meow and similar for quite some time ( I see a ref from 2017 in nodejs/node-eps#57 (comment) ) |
commented
Oct 6, 2020
|
After bisecting, this PR is the reason that node-gyp's test suite is failing in CITGM on master and the current v15.0.0-proposal (#35014, cc @BethGriggs). The test suite passes on Node.js 14. @nodejs/modules-active-members is this expected to break for CJS? This was documented as being a documentation only deprecation. |
commented
Oct 6, 2020
|
@richardlau this looks like whenever the deprecated form landed it didn't add back a setter, to my knowledge there was no intent to prevent assignment in CJS. This looks like a bug and we need to add back a setter, right now https://github.com/iarna/require-inject/blob/b1cc122fa34741a5d60ad4c26e839fd9bbb7a61b/index.js#L36 is failing due to the lack of setter. changing node/lib/internal/modules/cjs/loader.js Lines 226 to 233 in 8beef5e |
|
This PR moved the
EDIT: @bmeck beat me, sorry for the repetition. |
commented
Oct 6, 2020
|
FYI this is about to go out in 12. |
commented
Oct 6, 2020
|
@guybedford The version of this change that's going out in 12 is #34592 (doc-only deprecation) |
commented
Oct 6, 2020
via email
|
Ah great, thanks for verifying!
…On Tue, Oct 6, 2020 at 10:46 Michaël Zasso ***@***.***> wrote:
@guybedford <https://github.com/guybedford> The version of this change
that's going out in 12 is #34592
<#34592> (doc-only deprecation)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#32217 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAESFSVVXPE47WUCW7UCWGTSJNJXXANCNFSM4LGAHYGQ>
.
|
This feature does not work when a module is imported using ECMAScript modules
specification, therefore it is deprecated.
This has been discussed during Node.js Modules Team Meeting 2020-03-11; the main issue with this feature is that users are using it to check if the current module is the entry point, but that breaks when a CJS module is imported using ESM loader. Also its behaviour is kind of counterintuitive because of CJS cache.
This PR contains a breaking change:
Object.keys(module).includes('parent')used to betrue, and is nowfalse. Hopefully this can get merged before v14 feature freeze.Fixes: nodejs/modules#469
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes