when i try exec my code with npx ts-node index.ts
here is the message
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module:
C:\Users\harri\Desktop\lucca\node_modules\ora\index.js require()
of ES modules is not supported.
require() of
C:\Users\harri\Desktop\lucca\node_modules\ora\index.js from
C:\Users\harri\Desktop\lucca\index.ts is an ES module file as it is a .js
file whose nearest parent package.json contains "type": "module" which
defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or
remove "type": "module" from C:\Users\harri\Desktop\lucca\node_modules\ora\package.json.
Hello I would like to use ora (version6) with a index.ts file instead of index.ts file.
i am trying to use a typescript file to launch the spinner in my terminal :
// npm init --yes // npm install ora // npm install -D @types/ora ts-node typescript // tsc --init
// in the package.json file i add : "type": "module", // in the tsconfig.json file i have : "module": "commonjs" and "moduleResolution": "node"
// here the content of my index.ts //-------------------------- import ora from 'ora';
const spinner = ora('Loading unicorns').start();
setTimeout(() => { spinner.color = 'yellow'; spinner.text = 'Loading rainbows'; }, 1000);
//--------------------------
when i try exec my code with npx ts-node index.ts here is the message
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module:
C:\Users\harri\Desktop\lucca\node_modules\ora\index.js require() of ES modules is not supported.
require() of C:\Users\harri\Desktop\lucca\node_modules\ora\index.js from C:\Users\harri\Desktop\lucca\index.ts is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Users\harri\Desktop\lucca\node_modules\ora\package.json.