How to ship in CJS format when my package has pure ESM package dependencies?
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 275
- PR merge metrics
- No merged PRs in 30d
Description
index.ts:
```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. (/Users/zhangjiawei/Desktop/github-downloader/dist/index.js:47:26) {
code: 'ERR_REQUIRE_ESM'
}
```
Contributor guide
Assessment
This issue has not been assessed yet.