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

[Nuxt 3 Integration] Adding Unlighthouse to a Nuxt 3 project causes it to crash #13

Closed
Redemption198 opened this issue Apr 19, 2022 · 4 comments

Comments

@Redemption198
Copy link

Redemption198 commented Apr 19, 2022

Installing Unlighthouse following the instructions causes the Nuxt server to crash. It is probably caused by a dependency issue, installing unlighthouse adds the std-env@^2.3.0 package required by @nuxt/cli@^2.15.8 and @nuxt/config@2.15.8 which can't be installed on a Nuxt 3 project (Nuxt 3 uses std-env@^3.x.x). I can't provide a reproduction on codesandbox or stackblitz because the CHROME_PATH variable can't be set.

The error:
[worker reload] [worker init] Named export 'isWindows' not found. The requested module 'file:///home/user/Documents/folder/project-dir/node_modules/std-env/index.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'file:///home/user/Documents/folder/project-dir/node_modules/std-env/index.js';
const { provider, isWindows } = pkg;

import { provider, isWindows } from 'node_modules/std-env/index.js';
^^^^^^^^^
SyntaxError: Named export 'isWindows' not found. The requested module 'node_modules/std-env/index.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'node_modules/std-env/index.js';
const { provider, isWindows } = pkg;

at ModuleJob._instantiate (node:internal/modules/esm/module_job:127:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:193:5)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
at async loadESM (node:internal/process/esm_loader:88:5)
at async handleMainPromise (node:internal/modules/run_main:61:12)

@harlan-zw
Copy link
Owner

Hey @Redemption198

Thanks for taking the time to make this issue and looking into it. I've identified the issue and pushed up a fix in 0.3.22.

Please let me know if you have anymore issues :)

@Redemption198
Copy link
Author

Hey @Redemption198

Thanks for taking the time to make this issue and looking into it. I've identified the issue and pushed up a fix in 0.3.22.

Please let me know if you have anymore issues :)

Thank you for the quick fix, it works perfectly now! And also for creating this awesome tool!

Would it be possible to only throw a warning when the CHROME_PATH variable isn't set? Maybe displaying a message saying that unlighthouse requires Chrome to work and is disabled until installed.

@harlan-zw
Copy link
Owner

There should already be handling for this case, see: https://github.com/harlan-zw/unlighthouse/blob/main/packages/core/src/resolveConfig.ts#L90

It uses https://github.com/GoogleChrome/chrome-launcher first, which uses the CHROME_PATH variable I guess? If that fails, it tries to find a puppeteer dependency, which is recommended in the docs to install if you don't have chrome. Finally it should throw an error

     logger.fatal('Failed to find a chrome / chromium binary to run. Add the puppeteer dependency to your project to resolve.', e)
     logger.info('Run the following: \`npm install -g puppeteer\`')
     process.exit(0)

Is there a reliable way to bypass this?

@Redemption198
Copy link
Author

The CHROME_PATH error was: ERROR Cannot start nuxt: The CHROME_PATH environment variable must be set to a Chrome/Chromium executable no older than Chrome stable.

I was getting the error because I'm on a fresh install of Linux and didn't have any chrome/chromium browser installed, I tried installing ungoogled chromium but it didn't recognize it, while installing regular chrome from the rpm repository works fine.

Now I'm facing new errors, I had to force a fresh installation of Nuxt due to the RC0 release.
If I use yarn, unlighthouse can't find the following packages: @unlighthouse/core, @unlighthouse/webpack and @unlighthouse/vite

(Installing each package manually "fixes" the issue)

This is inside node_modules
picture

If instead I use npm I get this error Unsupported URL Type "link:": link:../../packages/core

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

2 participants