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

cliui dependency error #383

Closed
4 tasks done
nijinekoyo opened this issue Jan 16, 2024 · 11 comments
Closed
4 tasks done

cliui dependency error #383

nijinekoyo opened this issue Jan 16, 2024 · 11 comments

Comments

@nijinekoyo
Copy link

Describe the bug

require() of ES Module error when trying to build the project, caused by dependency on cliui
Use the solution in the documentation to fix it but it fails.

Log

$ electron-builder install-app-deps

project\node_modules\cliui\build\index.cjs:291
const stringWidth = require('string-width');
                    ^
Error [ERR_REQUIRE_ESM]: require() of ES Module project\node_modules\string-width\index.js from project\node_modules\cliui\build\index.cjs not supported.
Instead change the require of index.js in project\node_modules\cliui\build\index.cjs to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (project\node_modules\cliui\build\index.cjs:291:21)
    at Object.<anonymous> (project\node_modules\yargs\build\index.cjs:1:60678)
    at Object.<anonymous> (project\node_modules\yargs\index.cjs:5:30)
    at Object.<anonymous> (project\node_modules\electron-builder\out\builder.js:7:15)
    at Object.<anonymous> (project\node_modules\electron-builder\out\cli\cli.js:11:19)
    at Object.<anonymous> (project\node_modules\electron-builder\cli.js:4:1)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

Electron-Vite Version

^2.0.0

Electron Version

^28.1.1

Vite Version

^5.0.11

Validations

@nijinekoyo
Copy link
Author

cliui issues about this issue
yargs/cliui#138

@nijinekoyo
Copy link
Author

This problem occurred when trying to install vue-router@4. After testing, it seems that this error will occur as long as vue-router@4 is installed.

@nijinekoyo
Copy link
Author

electron-app.zip
This problem was successfully reproduced in this blank project

@nijinekoyo
Copy link
Author

Very strange, it seems that as long as tailwindcss is introduced first, and then vue-router is introduced, this problem will be triggered.

@alex8088
Copy link
Owner

cliui only supports esm, so you need to exclude it in externalizeDevPlugin or install in devDependencies.

@nijinekoyo
Copy link
Author

I developed it in an esm environment, and this bug still appears, and this bug is also related to the dependent installation order, which is very confusing.

@alex8088
Copy link
Owner

failed when executing electron-builder install-app-deps command?

@nijinekoyo
Copy link
Author

Yes, direct yarn install will also fail

@nijinekoyo
Copy link
Author

You can try the blank project I posted above

@alex8088
Copy link
Owner

It may be that cliui does not correctly handle the relationship between dependent packages(esm or cjs). You can remove postinstall script in your package.json. electron-builder install-app-deps command use to rebuild native node module, you can skip it first. If you cannot use it normally, it is recommended to replace it with other packages.

@nijinekoyo
Copy link
Author

ok

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