코딩/트러블 슈팅
[스토리북 에러] var stringWidth = require('string-width') Error [ERR_REQUIRE_ESM]
얌2
2023. 8. 10. 15:45
728x90
var stringWidth = require('string-width')
^
Error [ERR_REQUIRE_ESM]: require() of ES Module ...
code: 'ERR_REQUIRE_ESM'
yarn storybook을 하니 갑자기 이러한 문제가 발생했다.🤔 절대 경로를 설정하다가 맞닥뜨린 에러라 절대 경로 때문인가 했더니 아니었다.
해결 방법은 다음과 같다.
// package.json
{
...
"resolutions": {
"jackspeak": "2.1.1"
}
}
package.json 파일 안에 위 코드를 넣어도 오류가 날 경우, node_modules, yarn.lock을 지우고 다시 설치해 주면 된다.
rm -rf node_modules yarn.lock
yarn
다시 yarn storybook을 해주니 정상적으로 작동한다!
참고
https://github.com/storybookjs/storybook/issues/22431#issuecomment-1630086092
[Bug]: string-width dependency stops storybook from executing · Issue #22431 · storybookjs/storybook
Describe the bug I am using Storybook 7 with the automatically generated vite-react setup. When installing Storybook 7, yarn yields these dependency errors: yarn install v1.22.19 [1/5] 🔍 Validating...
github.com
728x90