-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
Failed loading plugins in current working directory #11671
Comments
node_modules
Thanks for filing @koh110! You're right this is a lighthouse-core problem with resolution of plugins when lighthouse is globally installed (like in this example). I'll go ahead and transfer this issue :) |
@patrickhulce Thanks for transferring! I checked $ lighthouse https://www.google.com --config-path=./config.js
Runtime error encountered: Unable to locate plugin: `lighthouse-plugin-field-performance`.
Tried to require() from these locations:
/usr/local/lib/node_modules/lighthouse/lighthouse-core/config
/home/koh110/dev/tmp/lighthouse-test/lighthouse-plugin-field-performance
/home/koh110/dev/tmp/lighthouse-test/lighthouse-plugin-field-performance
Error: Unable to locate plugin: `lighthouse-plugin-field-performance`.
Tried to require() from these locations: When I tried to fix lighthouse-core, I think that this code is not expecting to load plugins installed by npm. It might be expecting to load plugins written in local. If this idea is correct, I would have to modify this code. // First ...
try {
- return require.resolve(moduleIdentifier);
+ return require.resolve(moduleIdentifier, { paths: [process.cwd()] });
} catch (e) {}
// Second
const cwdPath = path.resolve(process.cwd(), moduleIdentifier);
try {
return require.resolve(cwdPath);
} catch (e) {}
const errorString = 'Unable to locate ' + (category ? `${category}: ` : '') +
`\`${moduleIdentifier}\`.
Tried to require() from these locations:
${__dirname}
${cwdPath}`;
if (!configDir) {
throw new Error(errorString);
}
// Finally, ...
const relativePath = path.resolve(configDir, moduleIdentifier);
try {
- return require.resolve(relativePath);
+ return require.resolve(moduleIdentifier, { paths: [configDir] });
} catch (requireError) {}
throw new Error(errorString + `
${relativePath}`); How do you feel about this code? |
IIUC, I think it might help if we outline all the cases we need to deal with...
I think that's our support today. Any cases I'm missing? |
Good call on fixing this!
This should work from the first I don't want to accidentally break relative paths for some existing case, so maybe the simplest thing is we can leave everything as-is and add a new step that does We could probably simplify more, but all the global/local/relative permutations make it difficult to get great test coverage on all these cases. Separate from that change, it would also be good to annotate which cases each check is covering (maybe with examples), as it's hard to remember what's doing what :) I think the first is trying to do all the modules-based stuff and the last two are meant mostly for paths, but it would be good to make that crystal clear. |
SGTM 👍 |
Thanks for reviews! I will try to add a new step and test. |
I'm having trouble
lhci collect
with plugins is failed.https://github.com/GoogleChrome/lighthouse#plugins
https://github.com/treosh/lighthouse-plugin-field-performance
Cause
This seems to be due to the
resolveModule
inlighthouse-core
.lighthouse/lighthouse-core/config/config-helpers.js
Line 178 in 378a31f
In my case, I would expect the plugin to be loaded under SECOND condition.
lhci
is installed in global and plugin exists in current working directory.Solution
I think
resolveModule
should be coded like this.https://nodejs.org/api/modules.html#modules_require_resolve_request_options
If I'm right, this is not
lhci
problem. I think I will send a PR tolighthouse-core
, is this correct?I followed the code and it appears since 2016.
#679
So I couldn't determine this was a bug or a specification.
The text was updated successfully, but these errors were encountered: