[storybook Error] const stringWidth = require('string-width');

heisje·2023년 8월 21일
2

이슈

https://github.com/storybookjs/storybook/issues/22431

에러코드

/Users/home/Documents/sw/storybook/learnstorybook-design-system/node_modules/cli-table3/src/utils.js:1
const stringWidth = require('string-width');
                    ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/home/Documents/sw/storybook/learnstorybook-design-system/node_modules/string-width/index.js from /Users/home/Documents/sw/storybook/learnstorybook-design-system/node_modules/cli-table3/src/utils.js not supported.
Instead change the require of index.js in /Users/home/Documents/sw/storybook/learnstorybook-design-system/node_modules/cli-table3/src/utils.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/home/Documents/sw/storybook/learnstorybook-design-system/node_modules/cli-table3/src/utils.js:1:21)
    at Object.<anonymous> (/Users/home/Documents/sw/storybook/learnstorybook-design-system/node_modules/cli-table3/src/table.js:2:15)
    at Object.<anonymous> (/Users/home/Documents/sw/storybook/learnstorybook-design-system/node_modules/cli-table3/index.js:1:18)
    at Object.<anonymous> (/Users/home/Documents/sw/storybook/learnstorybook-design-system/node_modules/@storybook/core-server/dist/index.js:113:8471)
    at Object.<anonymous> (/Users/home/Documents/sw/storybook/learnstorybook-design-system/node_modules/@storybook/cli/dist/generate.js:11:4494)
    at Object.<anonymous> (/Users/home/Documents/sw/storybook/learnstorybook-design-system/node_modules/@storybook/cli/bin/index.js:9:1)
    at Object.<anonymous> (/Users/home/Documents/sw/storybook/learnstorybook-design-system/node_modules/storybook/index.js:3:1) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v20.5.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

원인 추론

yarn 1의 의존성에서 문제가 일어나는 것 같고, pnpm또는 yarn의 버전업으로 해결을 한 사례가 많다.

내 해결 방법

  1. clean cache
  2. upgrade npm & yarn
  3. remove lock* files (yarn | npm)
  4. re-install packages
yarn cache clean --all

npm install -g npm@latest
npm install -g yarn@latest

rm node_modules/ yarn.lock package-lock.json

yarn
profile
김희제의 기술블로그

0개의 댓글