Skip to content

fix: use import-equals for slash to restore release uploads - #6

Open
JeanSilvany wants to merge 1 commit into
deploypulseio:mainfrom
JeanSilvany:fix/slash-cjs-import
Open

fix: use import-equals for slash to restore release uploads#6
JeanSilvany wants to merge 1 commit into
deploypulseio:mainfrom
JeanSilvany:fix/slash-cjs-import

Conversation

@JeanSilvany

Copy link
Copy Markdown

Problem

Every dpctl release-react / dpctl release fails at upload time:

Releasing update contents to DeployPulse:

management-sdk.js:330
  const relativePath = (0, slash_1.default)(path.relative(baseDirectoryPath, file));
                           ^
TypeError: (0 , slash_1.default) is not a function

The bundle is built successfully; the crash happens while walking the output folder to build the upload zip, so no release is ever created.

Cause

tsconfig.json does not enable esModuleInterop, so import slash from "slash" compiles to a bare require() while still reading .default:

const slash_1 = require("slash");        // no __importDefault helper
(0, slash_1.default)(...)                // .default is undefined

slash@1.0.0 (the pinned version) is CommonJS — module.exports = fn — so it has no .default.

Why not esModuleInterop: true

It would fix this import, but the codebase also uses import * as chalk and import * as yargs on CommonJS packages. With esModuleInterop those compile to __importStar, which replaces the module object with a synthesized namespace — a much wider behavioural change than this bug warrants.

Fix

Use the import-equals form, which is already the convention two lines above in the same file for q and superagent.

Verification

  • npx tsc builds clean; emitted output is const relativePath = slash(path.relative(...)).
  • packageFileFromPath() exercised directly against the built output: produces a valid zip with nested paths and forward slashes (which is what slash is there for — yazl rejects backslashes in metadata paths).
  • npm test: 107 passing / 8 failing, identical to the unmodified baseline. The 8 failures are pre-existing (local-cli/cli.js fixture path) and unrelated to this change.

Reproduced on Node v24.15.0, macOS.

tsconfig.json does not enable esModuleInterop, so `import slash from
"slash"` compiles to a bare require() while still reading `.default`:

    const slash_1 = require("slash");   // no __importDefault helper
    (0, slash_1.default)(...)           // .default is undefined

slash@1.0.0 is CommonJS (module.exports = fn) and has no `.default`, so
every release crashed while building the upload zip:

    TypeError: (0 , slash_1.default) is not a function
        at management-sdk.js:330

Enabling esModuleInterop would fix this import but also change
`import * as chalk` and `import * as yargs` into __importStar, replacing
those CommonJS module objects with synthesized namespaces — a far wider
behavioural change than this bug warrants.

The import-equals form is already the convention two lines above in the
same file, for q and superagent.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

1 participant