Open7

Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules/strip-ansi/index.js from

Hide(ひで)Hide(ひで)

nextjs14.0.4でjestを実行したら以下のエラー。

hide@hidenoMacBook-Pro with-prisma % yarn test
yarn run v1.22.19
$ jest
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/hide/hid3h/nextjs-jest-examples/with-prisma/node_modules/strip-ansi/index.js from /Users/hide/hid3h/nextjs-jest-examples/with-prisma/node_modules/string-width/index.js not supported.
Instead change the require of /Users/hide/hid3h/nextjs-jest-examples/with-prisma/node_modules/strip-ansi/index.js in /Users/hide/hid3h/nextjs-jest-examples/with-prisma/node_modules/string-width/index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/hide/hid3h/nextjs-jest-examples/with-prisma/node_modules/string-width/index.js:2:19)
    at Object.<anonymous> (/Users/hide/hid3h/nextjs-jest-examples/with-prisma/node_modules/cliui/build/index.cjs:291:21)
    at Object.<anonymous> (/Users/hide/hid3h/nextjs-jest-examples/with-prisma/node_modules/yargs/build/index.cjs:1:60678)
    at Object.<anonymous> (/Users/hide/hid3h/nextjs-jest-examples/with-prisma/node_modules/yargs/index.cjs:5:30)
    at _yargs (/Users/hide/hid3h/nextjs-jest-examples/with-prisma/node_modules/jest-cli/build/run.js:30:39)
    at buildArgv (/Users/hide/hid3h/nextjs-jest-examples/with-prisma/node_modules/jest-cli/build/run.js:149:26)
    at Object.run (/Users/hide/hid3h/nextjs-jest-examples/with-prisma/node_modules/jest-cli/build/run.js:124:24)
    at Object.<anonymous> (/Users/hide/hid3h/nextjs-jest-examples/with-prisma/node_modules/jest-cli/bin/jest.js:16:17)
    at Object.<anonymous> (/Users/hide/hid3h/nextjs-jest-examples/with-prisma/node_modules/jest/bin/jest.js:12:3)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Hide(ひで)Hide(ひで)

どうしてstrip-ansiの7系がインストールされているか。

yarn.lockを見てみる。

string-width@^5.0.1, string-width@^5.1.2:
  version "5.1.2"
  resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794"
  integrity sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==
  dependencies:
    eastasianwidth "^0.2.0"
    emoji-regex "^9.2.2"
    strip-ansi "^7.0.1"
wrap-ansi@^8.1.0:
  version "8.1.0"
  resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
  integrity sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==
  dependencies:
    ansi-styles "^6.1.0"
    string-width "^5.0.1"
    strip-ansi "^7.0.1"
"@isaacs/cliui@^8.0.2":
  version "8.0.2"
  resolved "https://registry.yarnpkg.com/@isaacs/cliui/-/cliui-8.0.2.tgz#b37667b7bc181c168782259bab42474fbf52b550"
  integrity sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==
  dependencies:
    string-width "^5.1.2"
    string-width-cjs "npm:string-width@^4.2.0"
    strip-ansi "^7.0.1"
    strip-ansi-cjs "npm:strip-ansi@^6.0.1"
    wrap-ansi "^8.1.0"
    wrap-ansi-cjs "npm:wrap-ansi@^7.0.0"

このあたり。

Hide(ひで)Hide(ひで)

isaacs/cliuiに関して。

jackspeak@^2.3.5:
  version "2.3.6"
  resolved "https://registry.yarnpkg.com/jackspeak/-/jackspeak-2.3.6.tgz#647ecc472238aee4b06ac0e461acc21a8c505ca8"
  integrity sha512-N3yCS/NegsOBokc8GAdM8UcmfsKiSS8cipheD/nivzr700H+nsMOxJjQnvwOcRYVuFkdH0wGUvW2WbXGmrZGbQ==
  dependencies:
    "@isaacs/cliui" "^8.0.2"
  optionalDependencies:
    "@pkgjs/parseargs" "^0.11.0"
Hide(ひで)Hide(ひで)
glob@^10.3.10:
  version "10.3.10"
  resolved "https://registry.yarnpkg.com/glob/-/glob-10.3.10.tgz#0351ebb809fd187fe421ab96af83d3a70715df4b"
  integrity sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==
  dependencies:
    foreground-child "^3.1.0"
    jackspeak "^2.3.5"
    minimatch "^9.0.1"
    minipass "^5.0.0 || ^6.0.2 || ^7.0.0"
    path-scurry "^1.10.1"
Hide(ひで)Hide(ひで)
sucrase@^3.32.0:
  version "3.35.0"
  resolved "https://registry.yarnpkg.com/sucrase/-/sucrase-3.35.0.tgz#57f17a3d7e19b36d8995f06679d121be914ae263"
  integrity sha512-8EbVDiu9iN/nESwxeSxDKe0dunta1GOlHufmSSXxMD2z2/tMZpDMpvXQGsc+ajGo8y2uYUmixaSRUc/QPoQ0GA==
  dependencies:
    "@jridgewell/gen-mapping" "^0.3.2"
    commander "^4.0.0"
    glob "^10.3.10"
    lines-and-columns "^1.1.6"
    mz "^2.7.0"
    pirates "^4.0.1"
    ts-interface-checker "^0.1.9"
Hide(ひで)Hide(ひで)

元はtailwind。
sucraseが以下のプルリクでバージョンアップして、globを10系にアップしたからか。
https://github.com/alangpierce/sucrase/pull/822

tailwindcss@^3.3.0:
  version "3.4.0"
  resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-3.4.0.tgz#045a9c474e6885ebd0436354e611a76af1c76839"
  integrity sha512-VigzymniH77knD1dryXbyxR+ePHihHociZbXnLZHUyzf2MMs2ZVqlUrZ3FvpXP8pno9JzmILt1sZPD19M3IxtA==
  dependencies:
    "@alloc/quick-lru" "^5.2.0"
    arg "^5.0.2"
    chokidar "^3.5.3"
    didyoumean "^1.2.2"
    dlv "^1.1.3"
    fast-glob "^3.3.0"
    glob-parent "^6.0.2"
    is-glob "^4.0.3"
    jiti "^1.19.1"
    lilconfig "^2.1.0"
    micromatch "^4.0.5"
    normalize-path "^3.0.0"
    object-hash "^3.0.0"
    picocolors "^1.0.0"
    postcss "^8.4.23"
    postcss-import "^15.1.0"
    postcss-js "^4.0.1"
    postcss-load-config "^4.0.1"
    postcss-nested "^6.0.1"
    postcss-selector-parser "^6.0.11"
    resolve "^1.22.2"
    sucrase "^3.32.0"