cli icon indicating copy to clipboard operation
cli copied to clipboard

Cannot upgrade from 8.17.2 (ERR_REQUIRE_ESM)

Open dsifford opened this issue 2 years ago • 7 comments

Describe the bug

We have the cli installed as a dependency to one of our repos that we have deployed on netlify and have been unable to upgrade the cli since 8.17.2 because it appears that one of the subdependencies use ESM imports.

Here's the full error:

[1/2] ⠄ netlify-cli
error <redacted_repo_path>/node_modules/netlify-cli: Command failed.
Exit code: 7
Command: node ./scripts/postinstall.js
Arguments:
Directory: <redacted_repo_path>/node_modules/netlify-cli
Output:
Success! Netlify CLI has been installed!

Your device is now configured to use Netlify CLI to deploy and manage your Netlify sites.

Next steps:

  netlify init     Connect or create a Netlify site from current directory
  netlify deploy   Deploy the latest changes to your Netlify site

For more information on the CLI run netlify help
Or visit the docs at https://cli.netlify.com

Error [ERR_REQUIRE_ESM]: require() of ES Module <redacted_repo_path>/node_modules/@netlify/build/node_modules/execa/index.js from <redacted_repo_path>/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/dist/utils/shell.js not supported.
Instead change the require of index.js in <redacted_repo_path>/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/dist/utils/shell.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (<redacted_repo_path>/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/dist/utils/shell.js:7:33)
    at Object.<anonymous> (<redacted_repo_path>/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/go/builder.js:6:17)
    at Object.<anonymous> (<redacted_repo_path>/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/go/index.js:12:19)
    at Object.<anonymous> (<redacted_repo_path>/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/index.js:10:30)
    at Object.<anonymous> (<redacted_repo_path>/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/dist/main.js:6:20)
    at async Promise.all (index 0) {
  code: 'ERR_REQUIRE_ESM'
}
Error [ERR_REQUIRE_ESM]: require() of ES Module <redacted_repo_path>/node_modules/@netlify/build/node_modules/execa/index.js from <redacted_repo_path>/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/dist/utils/shell.js not supported.
Instead change the require of index.js in <redacted_repo_path>/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/dist/utils/shell.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (<redacted_repo_path>/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/dist/utils/shell.js:7:33)
    at Object.<anonymous> (<redacted_repo_path>/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/go/builder.js:6:17)
    at Object.<anonymous> (<redacted_repo_path>/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/go/index.js:12:19)
    at Object.<anonymous> (<redacted_repo_path>/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/index.js:10:30)
    at Object.<anonymous> (<redacted_repo_path>/node_modules/@netlify/build/node_modules/@netlify/zip-it-and-ship-it/dist/main.js:6:20)
    at async Promise.all (index 0) {
  code: 'ERR_REQUIRE_ESM'
}

<redacted_repo_path>/node_modules/netlify-redirector/lib/redirects.js:116
      throw ex;
      ^
abort({"code":"ERR_REQUIRE_ESM"}) at Error
    at jsStackTrace (<redacted_repo_path>/node_modules/netlify-redirector/lib/redirects.js:1070:13)
    at stackTrace (<redacted_repo_path>/node_modules/netlify-redirector/lib/redirects.js:1087:12)
    at process.abort (<redacted_repo_path>/node_modules/netlify-redirector/lib/redirects.js:8502:44)
    at process.emit (node:events:390:28)
    at process.emit (node:domain:475:12)
    at emit (node:internal/process/promises:136:22)
    at processPromiseRejections (node:internal/process/promises:242:25)
    at processTicksAndRejections (node:internal/process/task_queues:97:32)
(Use `node --trace-uncaught ...` to show where the exception was thrown)

Steps to reproduce

  1. Have netlify-cli 8.17.2 installed in a non-module package.json (i.e., don't have type: "module" in package.json).
  2. Attempt to upgrade to latest.

Configuration

No response

Environment

  System:
    OS: macOS 12.2.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 8.30 GB / 32.00 GB
    Shell: 5.1.16 - /usr/local/bin/bash
  Binaries:
    Node: 16.13.0 - /usr/local/bin/node
    Yarn: 1.22.18 - /usr/local/bin/yarn
    npm: 8.1.0 - /usr/local/bin/npm

dsifford avatar Mar 28 '22 15:03 dsifford

Hi @dsifford, can you share which package manager are you using to upgrade? Is it npm or yarn? If npm can you trying using the latest version by running npm install -g npm?

erezrokah avatar Mar 28 '22 15:03 erezrokah

@erezrokah We're using yarn v1.22.18 and we have workspaces enabled.

dsifford avatar Mar 28 '22 15:03 dsifford

Ah, that's very useful. Can you provide the structure of your monorepo and where the CLI is referenced?

erezrokah avatar Mar 28 '22 16:03 erezrokah

Basic structure as follows:

.
├── package.json (root)
├── netlify.toml
├── cms
│   └── package.json
├── shared
│   └── package.json
└── web
    └── package.json (netlify-cli in devDependencies here)

dsifford avatar Mar 28 '22 16:03 dsifford

@erezrokah Just checking in here. Anything else I can provide to support you?

dsifford avatar Apr 04 '22 15:04 dsifford

Hi @dsifford, sorry I missed your last comment and also haven't had the chance to look at this.

Until we can get to the bottom of this issue, a possible workaround would be to try with npm. Latest version of npm supports workspaces too https://docs.npmjs.com/cli/v8/using-npm/workspaces

erezrokah avatar Apr 04 '22 15:04 erezrokah

@erezrokah No worries, just checking in as we typically upgrade our dependencies every monday and it was top of mind 😄

Until we can get to the bottom of this issue, a possible workaround would be to try with npm.

I've been lobbying hard for our org to switch to npm but as of right now it's not something we can do, unfortunately. 😞

dsifford avatar Apr 04 '22 15:04 dsifford

We're facing a similar issue since 13.1.1 (13.1.0 works fine) 13.1.1 results in an error in an unrelated depencency:

require() of ES Module /Users/<redacted>/node_modules/is-unicode-supported/index.js from /Users/<redacted>/packages/cz-lerna-changelog/node_modules/ora/index.js not supported.
Instead change the require of /Users/<redacted>/node_modules/is-unicode-supported/index.js in /Users/<redacted>/packages/cz-lerna-changelog/node_modules/ora/index.js to a dynamic import() which is available in all CommonJS modules.
/Users/<redacted>/node_modules/execa/index.js:212
                throw error;
                ^

matyasf avatar Apr 12 '23 20:04 matyasf