Actual behavior:
When I try to exec Prettier, I get the following error:
[project_path]/_esy/default/pnp.js:2177
for (const path of paths) {
^
TypeError: paths is not iterable
at Function.Module._findPath ([project_path]/_esy/default/pnp.js:2177:24)
at resolveMainPath (internal/bootstrap/pre_execution.js:447:28)
at Function.Module.runMain (internal/modules/cjs/loader.js:1138:24)
at internal/main/run_main_module.js:16:11
Expected behavior:
We should be able to exec it.
Additional steps to reproduce:
esy add prettier
esy prettier --write '**/*.md'
Added some extra notes from our investigation in Onivim in https://github.com/onivim/oni2/issues/945
looks like esy generates a pnp.js file from here:
https://github.com/esy/esy/blob/cee0381a84c14c4d68d3f1d8a6a5f4d46fecb363/esy-install/PnpJs.re#L944
...and in that spot, it 'monkey-patches' the Module._findPath module resolution logic. It seems that, in Node 13+, that paths can now be null.
Looking at the original implementation: https://github.com/nodejs/node/blob/efce655c0f1671d0e86b5c89092ac93db983ef94/lib/internal/modules/cjs/loader.js#L617 it seems it checks if the path is absolute, if it is, it just uses [''] for paths- otherwise it validates it is non-null and an array. Seems like we might need to bring some of that logic over to esy.
Seems specific to Node v13+ - @CrossR confirmed that Node 12 works, but Node 13 does not.
Looking at the original implementation: https://github.com/nodejs/node/blob/efce655c0f1671d0e86b5c89092ac93db983ef94/lib/internal/modules/cjs/loader.js#L617 it seems it checks if the path is absolute, if it is, it just uses [''] for paths- otherwise it validates it is non-null and an array. Seems like we might need to bring some of that logic over to esy.
Hardly scientific or thorough, but blindly copying that logic over into my generated pnp.js did allow esy bootstrap to run in Oni2.
Related to #930