estruyf / doctor

Doctor - Maintain your documentation on SharePoint without pain.
http://getdoctor.io
MIT License
112 stars 17 forks source link

[BUG] "ERROR: Cannot create property 'context' on string 'Command failed: localm365 login" due to paths in localm365 #141

Open bentolor opened 1 year ago

bentolor commented 1 year ago

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 _nodemodules 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:

  1. Install doctor inside WSL2 using yarn v1.22.19: sudo yarn global add @estruyf/doctor
  2. Run localm365
  3. 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.

bentolor commented 1 year ago

MAybethe approach should use sth. like this:

let packagePath = path.dirname(require.resolve("doctor/package.json"));

and navigate from there?