doctor
doctor copied to clipboard
[BUG] "ERROR: Cannot create property 'context' on string 'Command failed: localm365 login" due to paths in localm365
Describe the bug
After installing doctor via up-to-date Yarn v1.22 & NodeJS v18, the Doctor binary localm365 fails at all m365 operations, as it assumes a wrong node_modules location.
This can be identified at best while calling the binary itself:
/usr/local/share/.config/yarn/global/node_modules/@estruyf/doctor/bin/localm365:1
Error: Cannot find module '../node_modules/@pnp/cli-microsoft365/dist'
Require stack:
- /usr/local/share/.config/yarn/global/node_modules/@estruyf/doctor/bin/localm365
at Object.<anonymous> (/usr/local/share/.config/yarn/global/node_modules/@estruyf/doctor/bin/localm365:4:1)
at Module._compile (node:internal/modules/cjs/loader:1218:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
at Module.load (node:internal/modules/cjs/loader:1081:32)
at Module._load (node:internal/modules/cjs/loader:922:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/usr/local/share/.config/yarn/global/node_modules/@estruyf/doctor/bin/localm365'
]
}
Node.js v18.13.0
To Reproduce Steps to reproduce the behavior:
- Install doctor inside WSL2 using yarn v1.22.19:
sudo yarn global add @estruyf/doctor - Run
localm365 - See error
Workaround
Locally patching localm365 from require('../node_modules/@pnp/cli-microsoft365/dist'); to require('../../../@pnp/cli-microsoft365/dist'); solves the issue. But i think the right way to do is by other means to load the module.
MAybethe approach should use sth. like this:
let packagePath = path.dirname(require.resolve("doctor/package.json"));
and navigate from there?