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

[Bug]: ERR_REQUIRE_ESM error after upgrade from 6.5 to 7.1 (Win+Yarn+Webpack+Typescript) #23527

Closed
msnyder-msft opened this issue Jul 19, 2023 · 1 comment

Comments

@msnyder-msft
Copy link

Describe the bug

After upgrading my repository from storybook version 6.5.9 to 7.1.0 using the automigrations I am getting errors about ES Modules in a package that storybook consumes (cli-table3). yarn why cli-table3 reveals that it is brought in by the storybook project ("_project_#storybook#@storybook#cli#@storybook#core-server" depends on it). The migration indicated success and was able to complete. But now when I try to run yarn storybook I get the below error each time I try to run.

Version 6.5.9 is working great but I wanted to get to the current version.

###Error

const stringWidth = require('string-width');

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

###tsconfig.json

{
        "target": "es5",
        "jsx": "react",
        "lib": [
            "dom",
            "dom.iterable",
            "esnext"
        ],
        "module": "esnext",
        "moduleResolution": "node",
        "esModuleInterop": true,
        .....
}

error screenshot

Error message

To Reproduce

  • setup a project with version 6.5.9 using React, Yarn and Typescript, webpack.
  • Migrate to version 7.1.0

System

Environment Info:

  System:
    OS: Windows 10 10.0.22000
    CPU: (20) x64 Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz
  Binaries:
    Node: 16.20.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.19.4 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0), Chromium (113.0.1774.57)
  npmPackages:
    @storybook/addon-a11y: ^7.1.0 => 7.1.0
    @storybook/addon-console: ^2.0.0 => 2.0.0
    @storybook/addon-essentials: ^7.1.0 => 7.1.0
    @storybook/addon-interactions: ^7.1.0 => 7.1.0
    @storybook/react: ^7.1.0 => 7.1.0
    @storybook/react-webpack5: 7.1.0 => 7.1.0
    @storybook/testing-library: ^0.2.0 => 0.2.0

Additional context

No response

@valentinpalkovic
Copy link
Contributor

Duplicate of #22431. Please take a look at the following comment/workaround: #22431 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

2 participants