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

require() of ES Module node_modules\string-width\index.js from node_modules\wide-align\align.js not supported #21231

Closed
ineshbose opened this issue May 29, 2023 · 29 comments

Comments

@ineshbose
Copy link
Member

ineshbose commented May 29, 2023

Environment

Stackblitz environment and local


  • Operating System: Windows_NT
  • Node Version: v16.17.0
  • Nuxt Version: 3.5.2
  • Nitro Version: 2.4.1
  • Package Manager: yarn@1.22.19
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-e7ro7z?file=README.md

Describe the bug

Nuxt can't seem to work due to a dependency.

❯ yarn why wide-align
yarn why v1.22.19
[1/4] 🤔  Why do we have the module "wide-align"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "wide-align@1.1.5"
info Reasons this module exists
   - "nuxt#nitropack#@vercel#nft#@mapbox#node-pre-gyp#npmlog#gauge" depends on it
   - Hoisted from "nuxt#nitropack#@vercel#nft#@mapbox#node-pre-gyp#npmlog#gauge#wide-align"
info Disk size without dependencies: "16KB"
info Disk size with unique dependencies: "188KB"
info Disk size with transitive dependencies: "344KB"
info Number of shared dependencies: 4
✨  Done in 0.80s.

Now I refresh the lock-file multiple times. Take the Stackblitz - I refresh the lockfile there, and it works, but then I copy that lockfile locally and the issue persists there, while I refresh locally (and small chances it doesn't help) and copy to Stackblitz, then the container fails.

Additional context

No response

Logs

No response

Copy link
Member

The issue here seems to be caused by your package manager. See the following logs from the stackblitz:

CleanShot 2023-05-30 at 12.26.43.png

The actual version of string-width installed by yarn is v5 which seems to be incompatible with wide-align.

I'm afraid this isn't a Nuxt issue we can resolve.

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale May 30, 2023
@patrick-ve
Copy link

@danielroe, any ideas on how to ensure we can use an older version of string-width? I tried yarn clear cache, deleting all node_modules, lockfiles and manually setting version "^4.2.3" of string-width as a dependency, but all of this seems to fail unfortunately

@danielroe
Copy link
Member

You can use yarn resolutions.

@patrick-ve
Copy link

I can confirm that adding the following to package.json will resolve the issue:

"resolutions": {
    "string-width": "4.2.3"
 }

@szulcus
Copy link

szulcus commented Jun 21, 2023

I have the same error. For me yarn resolutions not working :/
Without resolutions:

$ yarn
yarn install v1.22.19
[1/4] Resolving packages...
warning Lockfile has incorrect entry for "string-width@^5.1.2". Ignoring it.
warning Lockfile has incorrect entry for "string-width@^5.0.1". Ignoring it.
warning Lockfile has incorrect entry for "string-width@^5.0.0". Ignoring it.

When I have "string-with": "2.2.3":

$ yarn
yarn install v1.22.19
[1/4] Resolving packages...
warning Resolution field "string-width@4.2.3" is incompatible with requested version "string-width@^5.1.2"
warning Resolution field "string-width@4.2.3" is incompatible with requested version "string-width@^5.0.1"
warning Resolution field "string-width@4.2.3" is incompatible with requested version "string-width@^5.0.0"

When I have "string-with": "5.0.0":

$ yarn
yarn install v1.22.19
[1/4] Resolving packages...
warning Resolution field "string-width@5.0.0" is incompatible with requested version "string-width@^5.1.2"
warning Resolution field "string-width@5.0.0" is incompatible with requested version "string-width@^5.0.1"
warning Resolution field "string-width@5.0.0" is incompatible with requested version "string-width@^4.1.0"
warning Resolution field "string-width@5.0.0" is incompatible with requested version "string-width@^4.2.0"
warning Resolution field "string-width@5.0.0" is incompatible with requested version "string-width@^4.2.0"
warning Resolution field "string-width@5.0.0" is incompatible with requested version "string-width@^4.1.0"
warning Resolution field "string-width@5.0.0" is incompatible with requested version "string-width@^4.2.3"
warning Resolution field "string-width@5.0.0" is incompatible with requested version "string-width@^4.1.0"
warning Resolution field "string-width@5.0.0" is incompatible with requested version "string-width@^4.2.3"
warning Resolution field "string-width@5.0.0" is incompatible with requested version "string-width@^4.2.0"
warning Resolution field "string-width@5.0.0" is incompatible with requested version "string-width@^4.1.0"
warning Resolution field "string-width@5.0.0" is incompatible with requested version "string-width@^4.2.3"
warning Resolution field "string-width@5.0.0" is incompatible with requested version "string-width@^1.0.2 || 2 || 3 || 4"
warning Resolution field "string-width@5.0.0" is incompatible with requested version "string-width@^4.2.3"
warning Resolution field "string-width@5.0.0" is incompatible with requested version "string-width@^4.2.3"

I still have this error and can't start my project 😥

@ObicaFF
Copy link

ObicaFF commented Sep 4, 2023

Is this an actual issues? Is there a solution to the problems? This applies not only with nuxt, unfortunately. And also nest js, with the nest-modules/mailer library.😥

divasilevski added a commit to divasilevski/nuxt-starter that referenced this issue Sep 22, 2023
@karadanay7
Copy link

Is this an actual issues? Is there a solution to the problems? This applies not only with nuxt, unfortunately. And also nest js, with the nest-modules/mailer library.😥
I solved it by removing yarn-lock file and node modules firstly but later i got the same issue during deployment then
I solved the issue by changing my package manager to npm from yarn .now i am able to deploy my site without any issue. I hope this works for you too.

@robinbeatty
Copy link

+1 for struggling with this error

@urielb
Copy link

urielb commented Nov 13, 2023

+1, still happening, although using the resolution, removing the yarn.lock and node_modules folder, it worked, even though it warned against an incompatibility between requested versions.

wide-align, which is used by npmlog, which is used by vite, eventually, forces the use of string-width<5, which from what I understand, was a dependency that yarn failed to comply with, causing the error.

from wide-align package.json:

"//": "But not version 5 of string-width, as that's ESM only",
  "dependencies": {
    "string-width": "^1.0.2 || 2 || 3 || 4"

Again, using the resolutions seems to be working, as long as you don't have a breaking dependency with the string-width ^5, it should be fine, but it can be really annoying. Wide-align has been inactive for over 2 years now, I doubt we will have a fix from them anytime soon. I might make a PR later to fix it

@eylonshm
Copy link

1.Add this code inside package.json:

"resolutions": {
    "jackspeak": "2.1.1"
 }
  1. Remove node_modules folder and yarn.lock package.lock files.
  2. Run npm/yarn install.

Worked for me :)

@mrleblanc101
Copy link

Still an issue for us

@hamrayev04
Copy link

rm -rf node_modules
rm -rf yarn.lock
yarn
yarn dev

@luckylooke
Copy link

luckylooke commented Jan 30, 2024

I have clean new install of nuxt.. added testing setup by following installation from docs here. Hit the error right away.

tried solution:

"resolutions": {
    "string-width": "4.2.3"
 }

but it hits next module... and I don't like the solution I would expect basic setup to work without hacks :/

Reproduced here: https://stackblitz.com/edit/nuxt-examples-g9ej3w?file=package.json

Thnks for any further hints 👍

EDIT:
I have find out that it is caused by installing "@vue/test-utils": "^2.4.4", package 😮

but it is in your docs to install it 🤔

yarn add --dev @nuxt/test-utils vitest @vue/test-utils happy-dom playwright-core

@qiuzman
Copy link

qiuzman commented Jan 31, 2024

Any fix yet? This has killed multiple projects of mine when trying to deploy to azure static web apps. Can use locally but deploying is the problem!!

imphil added a commit to fossi-foundation/fossi-foundation-web that referenced this issue Jan 31, 2024
* Pin to nuxt/image 1.2.0, since 1.3.0 breaks IPX rendering.
  Most likely due to nuxt/image#1177.
* Add an explicit resolution for jackspeak to work around
  nuxt/nuxt#21231.
imphil added a commit to fossi-foundation/fossi-foundation-web that referenced this issue Jan 31, 2024
* Pin to nuxt/image 1.2.0, since 1.3.0 breaks IPX rendering.
  Most likely due to nuxt/image#1177.
* Add an explicit resolution for jackspeak to work around
  nuxt/nuxt#21231.
@danielroe
Copy link
Member

If you're still encountering this, you should be aware that this is a bug in yarn. See https://github.com/search?q=strip-ansi+string-width&type=issues.

This comment explains the issue and provides a workaround.

@karadanay7
Copy link

I also had the same issue with nuxt.js I suggest to change the package manager from yarn to npm. Remove node_modules and yarn-lock then npm install . It worked for me.

@RyanClementsHax
Copy link
Contributor

If it helps anyone encountering a similar error, when attempting to reproduce this issue, I was seeing a very odd error in code sandbox. When setting up a nuxt repo from scratch locally, everything worked fine for me (nuxt v3.10.0, @nuxt/image v1.3.0 at time of writing this).

tidnav added a commit to navikt/mine-aap that referenced this issue Feb 6, 2024
…pakkene fører til at yarn test krasjer etter oppgradering av deps. Se nuxt/nuxt#21231

Co-authored-by: Thomas Sebastian Rognes <thomas.sebastian.rognes@nav.no>
windx-foobar added a commit to agantelin/nuxt3-notifications that referenced this issue Feb 6, 2024
windx-foobar pushed a commit to windx-foobar/nuxt3-notifications that referenced this issue Feb 6, 2024
Updated:
— @kyvg/vue3-notification from 2 to latest 3 version
— other dependencies
— regenerate yarn lockfile (nuxt/nuxt#21231 (comment))

---------

Co-authored-by: agantelin <agantelin@gmail.com>
@VIXI0
Copy link

VIXI0 commented Feb 22, 2024

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

@hyvyys
Copy link

hyvyys commented Feb 22, 2024

Deleting node_modules and reinstalling worked for me. (Not using nuxt though, but vite).

@Mintimate
Copy link

After deleting node_modules and yarn.lock and then running yarn again to download node_modules, the error was gone. It worked very well 🎉.

@thezumrad
Copy link

In my case instead of yarn install override with pnpm install on vercel's deployment made it work.
Using Nuxt@3.11.1

@cesswhite
Copy link

I deleted node_modules and yarn-lock, then installed everything again with npm.
In Vercel, I override the command for install to npm i
This solved my problem

@athachai29
Copy link

athachai29 commented Mar 23, 2024

I came to confirm here. The below steps can resolve the issue.

Add this to package.json.

"resolutions": {
    "string-width": "4.2.3"
 }

And then run these commands.

rm -rf node_modules
rm -rf yarn.lock
yarn cache clean
yarn install

Problem solved. 💕

@developer239
Copy link

developer239 commented Mar 24, 2024

How many of the people recommending the deletion of yarn.lock actually work with production application? 🤣 The lock file is there for a reason. Deleting it is an insanity.

zunda-pixel added a commit to zunda-pixel/niabis-web that referenced this issue Apr 15, 2024
zunda-pixel added a commit to zunda-pixel/niabis-web that referenced this issue Apr 15, 2024
@lance-anderson
Copy link

If you're still encountering this, you should be aware that this is a bug in yarn. See https://github.com/search?q=strip-ansi+string-width&type=issues.

This comment explains the issue and provides a workaround.

@danielroe The root issue is fixed in current version of Yarn. Perhaps it'll be helpful for folks if the first comment in this thread directs them to the Yarn update instructions here: https://yarnpkg.com/getting-started/install#updating-yarn

yarn set version stable
yarn install

While the "resolutions" shim is a reasonable temporary fix, if you can update your version of Yarn that is the proper fix.

@RomanSkrypnik
Copy link

Still facing this issue :\

@navidshad
Copy link

navidshad commented May 5, 2024

Solution

I had the same issue on docker and came across this solution:
remove the yarn.lock from copy list and let the yarn use original package.json the issue resolved.

In my case seems the yarn.lock contained some metadata relative to my locale environment and wont be used on docker environment.

@mrleblanc101
Copy link

@navidshad This is not a solution, that is terrible advice.

@danielroe
Copy link
Member

To be clear, this is a yarn bug with a workaround. And the bug has been fixed in a newer version of yarn.

See #21231 (comment)

@nuxt nuxt locked as resolved and limited conversation to collaborators May 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests