Port Node.js loader plugin fixes from d2c

Fixes #18235, #18236.