miyagi-dev / vscode-miyagi

VS Code extension for miyagi.
https://marketplace.visualstudio.com/items?itemName=fynn.miyagi
MIT License
2 stars 1 forks source link

More helpful error message when encountering missing modules while reading `.miyagi.js` #388

Open schalkneethling opened 1 month ago

schalkneethling commented 1 month ago

I just installed the extension in VSCode and got the following error:

2024-07-11 22:24:09.496 [info] Error: Cannot find module '@miyagi/twig-drupal'

VSCode Details

Version: 1.91.0 (Universal)
Commit: ea1445cc7016315d0f5728f8e8b12a45dc0a7286
Date: 2024-07-01T18:54:18.541Z
Electron: 29.4.0
ElectronBuildId: 9728852
Chromium: 122.0.6261.156
Node.js: 20.9.0
V8: 12.2.281.27-electron.0
OS: Darwin arm64 23.5.0
mvsde commented 1 month ago

Thank you for reporting. This usually means that npm dependencies are not yet installed and the extension encountered a missing module when trying to read the .miyagi.js configuration.

Can you try installing npm dependencies and then run the “miyagi: Reload” command from the VS Code Command Palette?

I’ll put it on my to do list to output a more helpful error message with the above-mentioned information.

schalkneethling commented 1 month ago

miyagi: Reload

Aha! I found what the problem was here. I installed it at the root of a Circle Dot based project. Here it throws the error no matter whether the dependencies are already installed or not. When I open VSCode to just the relevant theme (web/themes/custom/theme), everything works as expected.

I wonder whether one could add the ability to provide a setting that is the path to a theme directory and the extension would then look for the NPM modules inside this directory. I would be happy to contribute if this makes sense. Thanks!

mvsde commented 1 month ago

In theory the extension supports miyagi projects that are not in the root folder and even multiple projects opened at the same time.

The extension searches for all .miyagi.js or .miyagi.json files in the currently opened workspace and uses the miyagi config file to determine what a “project root” is:

https://github.com/miyagi-dev/vscode-miyagi/blob/c25b736f650c62b16010a1a22d2ae7dc4a9fbcff/src/lib/projects.ts#L46

I’m not sure why this didn’t work in your case 🤔

schalkneethling commented 1 month ago

In theory the extension supports miyagi projects that are not in the root folder and even multiple projects opened at the same time.

The extension searches for all .miyagi.js or .miyagi.json files in the currently opened workspace and uses the miyagi config file to determine what a “project root” is:

https://github.com/miyagi-dev/vscode-miyagi/blob/c25b736f650c62b16010a1a22d2ae7dc4a9fbcff/src/lib/projects.ts#L46

I’m not sure why this didn’t work in your case 🤔

I will create a fresh clone over the weekend and try it again to see if I can replicate.