这是indexloc提供的服务,不要输入任何密码
Skip to content

How to ship in CJS format when my package has pure ESM package dependencies? #628

@holazz

Description

@holazz

index.ts:

import ora from 'ora'

const spinner = ora('Starting...').start()
spinner.succeed('Done!')

run tsup index.ts --format cjs,esm && node dist/index.js and get error:

var import_ora = __toESM(require("ora"));
                         ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/zhangjiawei/Desktop/github-downloader/node_modules/.pnpm/ora@6.1.0/node_modules/ora/index.js from /Users/zhangjiawei/Desktop/github-downloader/dist/index.js not supported.
Instead change the require of /Users/zhangjiawei/Desktop/github-downloader/node_modules/.pnpm/ora@6.1.0/node_modules/ora/index.js in /Users/zhangjiawei/Desktop/github-downloader/dist/index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/zhangjiawei/Desktop/github-downloader/dist/index.js:47:26) {
  code: 'ERR_REQUIRE_ESM'
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions