2

I have chrome, LTS version of Node, and lighthouse already installed but get the following error when I try to run an audit:

/usr/local/lib/node_modules/lighthouse/lighthouse-core/lib/url-shim.js:36
class URLShim extends URL {
                      ^

ReferenceError: URL is not defined
    at Object.<anonymous> (/usr/local/lib/node_modules/lighthouse/lighthouse-core/lib/url-shim.js:36:23)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/lighthouse/lighthouse-core/lib/network-request.js:14:13)
    at Module._compile (module.js:652:30)

After installing all that is required, I try to test it and get the above error.

lighthouse https://www.bbc.co.uk

As I understand it you type lighthouse on the command line followed by the url of the site you're trying to run an audit against. But I keep getting :

ReferenceError: URL is not defined.

Am I doing something wrong. PLEASE HELP.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
George
  • 29
  • 1
  • 4

1 Answers1

5

I had the same issue. Your node version is outdated. Check it by running node --version

If it's less than 10, then you've found your problem.

https://nodejs.org/api/globals.html#globals_url

To update node:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

Then check you node version again:

node --version

Optionally, you can also install latest with sudo n latest , but I would recommend going with stable.

  • Hey justalazyprogrammer thanks for responding. I actually got the issue resolved. My linux system came with version 8 pre-installed, deleted it and installed version 10. I can now run lighthouse from the command line. Cheers. – George Nov 08 '19 at 07:28
  • Hey! Thank for the response. I actually got a new laptop just between my reply and now, so I re-installed node. For whatever reason, 8 gets installed by default. Not sure where that is coming from (if someone knows why let me know) – justalazyprogrammer Nov 10 '19 at 21:09
  • Hey, I have the same issue. I have put the command in a bash script. When I run the script, everything goes smoothly. When I run it as a cron job, I get the error. It's strange. Any ideas? node --version v12.18.3 – Vasiliki Aug 19 '20 at 12:43
  • I think your crontab is using a different environment. Take a look at this thread https://stackoverflow.com/questions/2135478/how-to-simulate-the-environment-cron-executes-a-script-with – justalazyprogrammer Aug 20 '20 at 17:50