Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 30, 2025

Node.js ESM doesn't support named imports from CommonJS modules. When bundling gitly to ESM format, the import { rm } from 'shelljs' pattern causes a runtime error.

Changes

  • Changed shelljs import in src/utils/download.ts from named import to default import with destructuring
  • Updated test files for consistency
// Before
import { rm } from 'shelljs'

// After
import shelljs from 'shelljs'
const { rm } = shelljs

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • google.com
    • Triggering command: /usr/local/bin/node /usr/local/bin/node /home/REDACTED/work/gitly/gitly/node_modules/jest-worker/build/workers/processChild.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>ESM: Named export 'rm' not found</issue_title>
<issue_description>Consider the following script:

// index.ts
import gitly from 'gitly';

gitly("https://github.com/iwatakeshi/gitly", process.cwd(), {});

Building it with various bundlers to ESM works fine:

  • npx esbuild --format=esm index.ts
  • npx tsup --format esm index.ts
  • npx tsdown --format esm index.ts

However, any of the resulting scripts will produce a runtime error:

import { rm as rm2 } from "shelljs";
         ^^
SyntaxError: Named export 'rm' not found. The requested module 'shelljs' 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 'shelljs';
const { rm: rm2 } = pkg;

    at #_instantiate (node:internal/modules/esm/module_job:254:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:369:5)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:691:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:101:5)

Node.js v24.11.0

When I change the build-target to CommonJS, everything works as desired. Following the suggestion from the error message will likely fix the issue.

Update This error is NodeJS-specific. Since you checked in a lockfile for Bun, I tested it there aswell and don't get an error.</issue_description>

<agent_instructions>Analyze the issue and introduce a fix</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits November 30, 2025 21:57
Changed shelljs import from named import to default import with
destructuring to fix "Named export 'rm' not found" error in Node.js
ESM context.

The issue occurs because shelljs is a CommonJS module, and Node.js
doesn't support named exports from CommonJS modules when running ESM
code.

Changed from:
  import { rm } from 'shelljs'
To:
  import shelljs from 'shelljs'
  const { rm } = shelljs

Also updated test files for consistency.

Co-authored-by: iwatakeshi <1505448+iwatakeshi@users.noreply.github.com>
Co-authored-by: iwatakeshi <1505448+iwatakeshi@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix named export 'rm' issue in ESM Fix ESM named export 'rm' not found error with shelljs Nov 30, 2025
Copilot AI requested a review from iwatakeshi November 30, 2025 22:00
@codecov
Copy link

codecov bot commented Nov 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.38%. Comparing base (cb740c2) to head (a0f2c1e).
⚠️ Report is 7 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #46      +/-   ##
==========================================
+ Coverage   93.36%   93.38%   +0.02%     
==========================================
  Files          12       12              
  Lines         241      242       +1     
  Branches       65       65              
==========================================
+ Hits          225      226       +1     
  Misses         15       15              
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@iwatakeshi iwatakeshi marked this pull request as ready for review November 30, 2025 22:05
@iwatakeshi iwatakeshi merged commit be7cb15 into master Nov 30, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ESM: Named export 'rm' not found

2 participants