kelektiv/node.bcrypt.js

Errors in dep 'string-width' after updating packages

serjo96 opened this issue · 6 comments

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

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
  1. cd demo
  2. 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.

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 :
nuxt/nuxt#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 :(

I also have the same problem

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

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

  • Removing yarn.lock only works for one time. Every time when I have to run yarn install, I have to delete yarn.lock which is not solution but rather work around only.
  • Adding
"resolutions": {
    "string-width": "4.2.3"
} 

did not work. Might be because of limitation https://classic.yarnpkg.com/lang/en/docs/selective-version-resolutions/#toc-limitations-Caveats

Did anyone resolve this issue?