[v12.x backport] CJS exports detection
This backports the CJS exports detection from https://github.com/nodejs/node/pull/35249 and the error message adjustments from https://github.com/nodejs/node/pull/35426 for 12.x.
This PR is based to the modules backports PR at https://github.com/nodejs/node/pull/35385 so should land after that.
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
documentation is changed or added -
commit message follows commit guidelines