Skip to content
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

Error: Cannot find module 'lighthouse/lighthouse-core/lib/environment.js' #5

Closed
skloiber-sz opened this issue Feb 12, 2017 · 18 comments
Assignees
Labels

Comments

@skloiber-sz
Copy link

Hi Addy,

when requiring the plugin in the webpack.config file and executing webpack I get this error message:

Error: Cannot find module 'lighthouse/lighthouse-core/lib/environment.js'

It seems that the node compatibility check was removed from lighthouse core.

Thanks,
Stefan

@addyosmani addyosmani self-assigned this Mar 6, 2017
@addyosmani addyosmani added the bug label Mar 6, 2017
@addyosmani
Copy link
Owner

Thanks for flagging this, @skloiber-sz. I'll check what we've changed upstream in Lighthouse and get this patched up in the module.

@RichAyotte
Copy link

'lighthouse/lighthouse-core/lib/environment.js' doesn't exist in lighthouse anymore. https://github.com/GoogleChrome/lighthouse/tree/master/lighthouse-core/lib

Is there a quick workaround before I dig too deep into this?

@screendriver
Copy link

Same issue here. Any workaround at the moment?

@carlkenne
Copy link

any news on this?

@paulirish
Copy link

This module is broken at the moment.

It will need some work to fix up.

Most of https://github.com/addyosmani/webpack-lighthouse-plugin/blob/master/src/lighthouse-bin.js can be nuked and replaced with https://github.com/GoogleChrome/lighthouse/tree/b354890076f2c077c5460b2fa56ded546cca72ee/docs#using-programmatically effectively.

I know addy is pretty busy right now.. Anyone wanna give this a shot?

@addyosmani
Copy link
Owner

I know addy is pretty busy right now.. Anyone wanna give this a shot?

My fault. Sorry for dropping the ball on this folks!

It will need some work to fix up.

If someone would like to help with a PR to update the plugin to use https://github.com/GoogleChrome/lighthouse/tree/b354890076f2c077c5460b2fa56ded546cca72ee/docs#using-programmatically directly that would be mucho awesome.

If not, I'll try to make some progress later in the week on rewriting.

@carlkenne
Copy link

carlkenne commented May 28, 2017

I'd love to help out, so I had a look at the code with the intention of fixing it.
However, if we use that example from the docs and nuke the rest from https://github.com/addyosmani/webpack-lighthouse-plugin/blob/master/src/lighthouse-bin.js we will loose some lighthouse functionality.
The problem is that some functionality resides in lighthouse-cli (like saveAssets, saveArtifacts, html generation, error handling, various config params...). Using the example (which goes straight to lighthouse-core) would bypass that.

Ideally I think that functionality should be extracted from lighthouse-cli/bin.ts to lighthouse-core (in the lighthouse repo). But to get this plugin working again I would instead need to copy that functionality from lighthouse-cli/bin.ts to this plugin before using the example code from the docs (similar to what Addy has done already, so code would just slightly change).
I could send a PR to show you what I mean.
Unless I'm missing something here?

@addyosmani
Copy link
Owner

saveAssets, saveArtifacts, html generation, error handling, various config params

Unless I'm mistaken I believe you're right. cc'ing in @samccone in case we're missing something obvious.

But to get this plugin working again I would instead need to copy that functionality from lighthouse-cli/bin.ts to this plugin before using the example code from the docs

Let's wait to hear from @paulirish and/or @samccone before doing this. On the Lighthouse side they've supportive of folks not needing to copy large pieces of functionality (a problem in the past) but I'm unsure short-term how much room there would be for them to add-in the other features we're using above.

Thanks for any time you're able to commit to helping here @carlkenne. With some luck we'll get a little clarity on next steps soon.

@paulirish
Copy link

Ah I see. looks like you're saving results to disk. Gotcha. Assuming that's something we want to continue to do here... i have an alternate proposal:

You could use runLighthouse from lighthouse-cli which kinda does all this work itself. Check it out: https://github.com/GoogleChrome/lighthouse/blob/5add27db28459f0c4f57b873bc7cb168af77bf75/lighthouse-cli/bin.ts#L174-L199

Based on what's currently needed from this plugin, that actually seems totally compatible. If you wanted to process the JSON results yourself, you'd need to pick and choose these methods a bit more.

@carlkenne
Copy link

Alright, I tried it and it works.
As a user I would assume that the plugin worked like the cli tool, so copying 20 or so lines from the beginning of bin.ts file would be needed (flags / config setup). Will work short term until lighthouse makes some changes to that part.

@paulirish
Copy link

@carlkenne that seems good.

in the future we'd like to improve consuming the module, so we'll use the implementation you do here as guidance for what public API we should expose.

@carlkenne
Copy link

@paulirish I tried it out in a real project today and failed.
It appears that when I require('lighthouse-cli/bin') the line with const cliFlags = getFlags(); is called and throws an error because no argv was provided from the command line (throw new Error('Please provide a url'); from cli-flags.ts).

It makes sense since I'm not using the command line and this code expects you to.
As I see it, the only way to go forward now is to copy the entire bin.ts and remove the const cliFlags = getFlags(); line (not a good long term solution). Or if someone could split this file in 2 in the lighthouse repo...

@paulirish
Copy link

cc @ebidel

@paulirish
Copy link

with GoogleChrome/lighthouse#2602 complete, this should be much more straightforward.

something like this:

const runLighthouse = require('lighthouse/lighthouse-cli/run.js').runLighthouse;

const flags = { 
  port: 0,
  chromeFlags: '',
  output: 'html'
};

runLighthouse(url, flags).then(results => {
  results....
});

The above requires this PR to land, but that should happen by the time you read this. :)

It will get the JSON passed back so you can evaluated it, but it'll also save the HTML report to disk.

@benjaminhoffman
Copy link

got this error this morning after giving lighthouse a shot in my webpack config. any thoughts on when this may be fixed?

@evenstensberg
Copy link
Collaborator

I'll get a fix to this by tomorrow @benjaminhoffman , sorry for the delay

@addyosmani
Copy link
Owner

addyosmani commented Sep 24, 2017 via email

@evenstensberg
Copy link
Collaborator

#7 Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants