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

ReferenceError: URL is not defined #8909

Closed
lubomirblazekcz opened this issue May 9, 2019 · 11 comments
Closed

ReferenceError: URL is not defined #8909

lubomirblazekcz opened this issue May 9, 2019 · 11 comments

Comments

@lubomirblazekcz
Copy link

Getting this error in my CI after updating to version 5.0.0, I think it has to do something with 94800e1

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

ReferenceError: URL is not defined
    at Object.<anonymous> (/usr/lib/node_modules/lighthouse/lighthouse-core/lib/url-shim.js:35: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/lib/node_modules/lighthouse/lighthouse-core/lib/network-request.js:14:13)
    at Module._compile (module.js:652:30)
child_process.js:644
    throw err;

Provide the steps to reproduce

lighthouse --chrome-flags="--disable-gpu --headless --no-sandbox" https://google.com --output json --output html --output-path ./.lighthouse/google.com_05-09-19-1557389996769.json

Environment Information

  • Affected Channels: CLI
  • Lighthouse version: 5.0.0
  • Node.js version: 8.11.1
  • Operating System: Ubuntu 17.10
@cristianoliveira
Copy link

cristianoliveira commented May 9, 2019

I was facing the same problem but I found out that the latest version of this package requires Node 10 or above.

Relevant links:
Breaking Changes - https://github.com/GoogleChrome/lighthouse/releases/tag/v5.0.0
PR - #8117

@lubomirblazekcz
Copy link
Author

@cristianoliveira thanks, I didn't notice that

@mobigaurav
Copy link

@evromalarkey You can try the previous version of lighthouse as ->

npm install -g lighthouse@4.0.0 --save-exact
or
switch to a newer node version >=10.0

@briosheje
Copy link

Updating / Switching to any node version above 10.0 solves the issue.

@bitrecipe
Copy link

Add this line at the top of script solved my issue
global.URL = require('url').URL;

@patrickhulce
Copy link
Collaborator

@bitrecipe while that might work right now, the only officially supposed node version moving forward is v10 LTS, so just be aware that future Lighthouse versions might end up breaking you unexpectedly if you're still on v8.

@bitrecipe
Copy link

@patrickhulce I know this is a shortcut method not the correct approach but it's works on Node.js version 8, if he still need Node.js version 8 for some reason

@Peitemoukiemena
Copy link

I am getting the same error.

node --version
v12.18.3

I added the command in a bash script. When I run the bash script, everything works well.
When I run the script as a cron job, I get the error URL is not defined.
Any ideas?

@patrickhulce
Copy link
Collaborator

When I run the script as a cron job, I get the error URL is not defined.

I'm guessing the node version used by the cron job is falling back to an older system version than the one used by you in a bash script. Check which node and make sure they're using the same?

@Peitemoukiemena
Copy link

Peitemoukiemena commented Aug 19, 2020

That is absolutely correct! From my terminal

 which node
/usr/local/bin/node

but from cron it's /usr/bin/node.

~$ /usr/bin/node --version
v8.10.0
~$ /usr/local/bin/node --version
v12.18.3

Any suggestions?

@Peitemoukiemena
Copy link

Peitemoukiemena commented Aug 19, 2020

I did something which I don't know if it was a good idea. I don't know how I could have removed or upgraded the /usr/bin/node old version, so I did the following.

sudo mv /usr/bin/node /usr/bin/node.old
sudo ln -s /usr/local/bin/node /usr/bin/node

and my command worked from the cron job.

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

No branches or pull requests

7 participants