sindresorhus / ora

Elegant terminal spinner
MIT License
9.08k stars 269 forks source link

How can i use ora in commonjs #200

Closed Joker0219 closed 2 years ago

Joker0219 commented 2 years ago

I am writing a node cli with typescript. I wanna use ora to log my processing, after using 'tsc' compiled my program, there are something worng:

error [ERR_REQUIRE_ESM]: require() of ES Module /xxx/rubest/packages/rubest-cli/node_modules/ora/index.js from /xxx/rubest/packages/rubest-cli/lib/eslint/index.js not supported. Instead change the require of /xxx/rubest/packages/rubest-cli/node_modules/ora/index.js in /xxx/rubest/packages/rubest-cli/lib/eslint/index.js to a dynamic import() which is available in all CommonJS modules. at Object. (/Users/gavin/Documents/front-end-for-speed/rubest/packages/rubest-cli/lib/eslint/index.js:44:29) at Object. (/Users/gavin/Documents/front-end-for-speed/rubest/packages/rubest-cli/lib/bin/cmds/eslint.js:4:16) at Object. (/Users/gavin/Documents/front-end-for-speed/rubest/packages/rubest-cli/lib/bin/cmds/index.js:16:32) at Object. (/Users/gavin/Documents/front-end-for-speed/rubest/packages/rubest-cli/lib/bin/index.js:18:30) { code: 'ERR_REQUIRE_ESM' }

Joker0219 commented 2 years ago

there is my TSconfig:

{ "compilerOptions": { "incremental": true, // 增量编译 // "tsBuildInfoFile": "./node_modules/ora", // 增量编译文件的存储位置 "diagnostics": false, // 打印编译信息

  "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */
  "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
  "outDir": "./lib", /* Redirect output structure to the directory. */
  "strict": true, /* Enable all strict type-checking options. */
  "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
  "allowSyntheticDefaultImports": true,
  "skipLibCheck": true, /* Skip type checking of declaration files. */
  "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */,
  "noFallthroughCasesInSwitch": true,
  "declaration": true,
  "moduleResolution": "node",
  "baseUrl": "./",
  "allowJs": true,
  "paths": {
    "@/*": [
      "./src/*"
    ]
  }
},
"include": [
  "./src",
  "./types.d.ts"
],
sindresorhus commented 2 years ago

You have to use an older version or wait for TS 4.6. See: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c