"Named export 'gt' not found." on netlify build @15.1.1

This happens on both build and deploy after I upgraded netlify-cli from 13.2.2 to 15.1.1. Reverting to previous version fixes the problem.

Full error is:

netlify build
file:///home/jlowery2663/.config/yarn/global/node_modules/gh-release-fetch/dist/index.js:5
import { gt } from 'semver';
         ^^
SyntaxError: Named export 'gt' not found. The requested module 'semver' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'semver';
const { gt } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)

Node.js v18.15.0

Not sure how this is a Netlify issue. Sounds like an incompatible package. How can we reproduce this issue?

An incompatible package that only manifests itself when upgrading the netlify-cli version?

Tell me what you need.

A sample project to reproduce the issue, along with the steps needs to trigger the problem would be something to start with.

Just ran into this when trying to upgrade the Netlify CLI package to the latest version (v15.3.1?). The error comes from Netlify’s postinstall script.

[4/4] Building fresh packages...
[-/3] ⠄ waiting...
[3/3] ⡀ netlify-cli
error [...]\node_modules\netlify-cli: Command failed.
Exit code: 1
Command: node ./scripts/postinstall.mjs
Arguments:
Directory: [...]\node_modules\netlify-cli
Output:
[...]/node_modules/gh-release-fetch/dist/index.js:5
import { gt } from 'semver';
         ^^
SyntaxError: Named export 'gt' not found. The requested module 'semver' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'semver';
const { gt } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
    at async postInstall ([...]/node_modules/netlify-cli/scripts/postinstall.mjs:29:35)
    at async [...]/node_modules/netlify-cli/scripts/postinstall.mjs:60:1

Found a github issue here: Unable to install netlify-cli using Yarn · Issue #5749 · netlify/cli · GitHub

1 Like