New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS Code extension errors with `Unable to start webhint...` even if everything is installed #1437

Closed
alrra opened this Issue Oct 23, 2018 · 6 comments

Comments

Projects
None yet
3 participants
@alrra
Member

alrra commented Oct 23, 2018

Especially if hint is installed globally, the VS Code extension won't work complaining: Unable to start webhint. Ensure you are using the latest version of the hint and @hint/configuration-development packages.

Even when the global installs are removed, and everything that is needed is installed locally, it doesn't always work (e.g.: I think I manage to make it work by reinstalling everything locally and restarting VS Code).

@molant

This comment has been minimized.

Member

molant commented Oct 23, 2018

We might want to disable the search in the global scope.

/cc @antross

@antross

This comment has been minimized.

Member

antross commented Oct 23, 2018

My guess on the need for the restart is that require has cached the global module so we keep getting it even once a local one is available:
https://stackoverflow.com/questions/9210542/node-js-require-cache-possible-to-invalidate

Official docs:
https://nodejs.org/api/modules.html#modules_caching
https://nodejs.org/api/modules.html#modules_require_cache

This could affect us even when everything is local (e.g. we load an outdated version of a module, the user updates via npm, and then we request it again, but still get the old one). We don't run into this outside of extension-vscode as we don't operate as a long-running process in most other contexts.

Per that SO thread, we can explicitly invalidate the cache by calling delete require.cache[moduleName].

@alrra @molant We can update extension-vscode to clear the cache for hint and other modules it loads directly, but I think as part of this loadResources should also be updated to forcibly clear the cache for a given module before loading it (possibly conditionally), thoughts?

@molant molant added this to the 1811-1 milestone Oct 29, 2018

@molant molant self-assigned this Nov 6, 2018

@molant

This comment has been minimized.

Member

molant commented Nov 6, 2018

So my plan with this is to try to repro it now that we shouldn't have issues with canvas anymore (pending PR merge), If this still happens then I'll nuke all the require cache that contains hint or @hint in the path when calling loadWebHint in server.ts.

How does that sound?

@antross

This comment has been minimized.

Member

antross commented Nov 6, 2018

This is definitely still possible so I'd plan on nuking the cache. I'd recommend updating the loadModule helper we created to load hint itself to always nuke the requested entry in the require cache as well before loading it.

@molant

This comment has been minimized.

Member

molant commented Nov 7, 2018

I've found a (the?) problem when the installation is global.
The way npm installs packages globally is different than locally. configuration-development depends on configuration-progressive-webapps.
Locally there isn't any problem because the structure is flatten:

  • node_modules/@hint/configuration-development
  • node_modules/@hint/configuration-progressive-webapps

but when installed globally it will be in the node_modules of configuration-development:

  • @hint/configuration-development/node_modules/@hint/configuration-progressive-webapps

and thus we can't find it.

I'm trying to figure out now what can be done.

molant added a commit to molant/hint that referenced this issue Nov 8, 2018

Fix: Find modules inside configurations
The main difference when installing webhint globally is that
`node_modules` content is not really flatten as the user needs to
install each package separatelly. This can cause some problems
findinging dependencies when they are nested. E.g.:
`configuration-development` downloads also
`configuration-progressive-webapps` but while this package will be at
the same level when installing webhint locally, when installing globally
it will be under `configuration-development`'s `node_modules` folder.

This change makes possible to find the packages under these
circumstances.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Fix webhintio#1437

@molant molant referenced this issue Nov 8, 2018

Merged

Fix/vscode #1484

2 of 2 tasks complete

@molant molant closed this in #1484 Nov 8, 2018

molant added a commit that referenced this issue Nov 8, 2018

Fix: Find modules inside configurations
The main difference when installing webhint globally is that
`node_modules` content is not really flatten as the user needs to
install each package separatelly. This can cause some problems
findinging dependencies when they are nested. E.g.:
`configuration-development` downloads also
`configuration-progressive-webapps` but while this package will be at
the same level when installing webhint locally, when installing globally
it will be under `configuration-development`'s `node_modules` folder.

This change makes possible to find the packages under these
circumstances.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Fix #1437
@molant

This comment has been minimized.

Member

molant commented Nov 9, 2018

For future selves, at the end I didn't nuke the cache. That scenario is interesting if we start proposing to update packages within the extension and is tracked in webhintio/rfcs#61

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment