kelektiv / node.bcrypt.js

bcrypt for NodeJs
MIT License
7.38k stars 510 forks source link

Errors in dep 'string-width' after updating packages #1023

Open serjo96 opened 5 months ago

serjo96 commented 5 months ago

At two project I found very strange problem, after update some packages bcrypt stars shoots in my project. Idk what is problem, I was try to change node, remove and install bcrypt, but all same, if remove yarn.lock, bcrypt correct install, but after restart project I receive some error like at install.

error /project/node_modules/bcrypt: Command failed.
Exit code: 1
Command: node-pre-gyp install --fallback-to-build
Arguments: 
Directory: /project/node_modules/bcrypt
Output:
/project/node_modules/wide-align/node_modules/string-width/index.js:2
const stripAnsi = require('strip-ansi');
                  ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /project/node_modules/strip-ansi/index.js from /project/node_modules/wide-align/node_modules/string-width/index.js not supported.
Instead change the require of /project/node_modules/strip-ansi/index.js in /project/node_modules/wide-align/node_modules/string-width/index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/project/node_modules/wide-align/node_modules/string-width/index.js:2:19) {
  code: 'ERR_REQUIRE_ESM'
}

node: 16.5 / 20.11.0 mac os Sonoma 14.2.1 (23C71) /docker with node.js Global packages:

info "node-gyp@10.0.1" has binaries:
   - node-gyp
info "node-pre-gyp@0.17.0" has binaries:
   - node-pre-gyp
StelFoog commented 5 months ago

I've encountered the same issue on an M2 MacBook (Sonoma 14.0).

My steps to reproduce are:

  1. yarn create next-app demo
    ✔ Would you like to use TypeScript? … Yes
    ✔ Would you like to use ESLint? … No
    ✔ Would you like to use Tailwind CSS? … Yes
    ✔ Would you like to use `src/` directory? … Yes
    ✔ Would you like to use App Router? (recommended) … Yes
    ✔ Would you like to customize the default import alias (@/*)? … No
  2. cd demo
  3. yarn add bcrypt

But if I, like @serjo96, remove yarn.lock before installing (either initially with yarn add bcrypt or reinstalling with rm -rf node_modules && yarn install) the installation works.

CaptainFalcon92 commented 4 months ago

Removing the lock file is not a solution, but rather a temporary work-around. The lock is there to protect your app packages versions and one should be able to add a package without updating the whole dependencies.

The error has been described by the nuxt community here : https://github.com/nuxt/nuxt/issues/21231

This is a Yarn only problem that either people solve by ignoring the lock file principle or replacing yarn by npm. Either way as people work around the issue i'm not sure how it will get fixed :(

VIXI0 commented 4 months ago

I also have the same problem

VIXI0 commented 4 months ago

The solution is to change the yarn version. corepack enable yarn set version berry yarn install

chhornponleu commented 4 months ago

I got it resolved by removing yarn.lock and reinstall again.

wm-rojen commented 3 months ago

Did anyone resolve this issue?