sindresorhus / ora

Elegant terminal spinner
MIT License
9.14k stars 270 forks source link

Ora doesn't compile with typescript #205

Closed digitalatcore closed 2 years ago

digitalatcore commented 2 years ago

am trying to build a CLI with nodejs and i tried to add some spinners in the command line using Ora. Unfortunately when i run tsc to build my JS 26 errors are thrown :

........ 
node_modules/ora/index.d.ts:269:9 - error TS1005: ';' expected.

269  frame(): string;
            ~

node_modules/ora/index.d.ts:270:1 - error TS1128: Declaration or statement expected.

270 }
    ~

Found 26 errors.

this my tsconfig file :

    {
  "compilerOptions": {
    "target": "es5",
    "lib": ["es2017", "es2015", "dom", "es6"],
    "module": "commonjs",
    "outDir": "./bin",
    "sourceMap": false,
    "strict": true,
    "moduleResolution": "node"
  },
  "include": ["src/**.ts"],
  "exclude": ["node_modules"]
}

I tried importing the module in multiple ways but it always seems to fail the build. thank you.

sindresorhus commented 2 years ago

Ora is an ESM module and you need to output to ESM, not CommonJS. You also need TS 4.7. Alternatively, use version 5.

https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

digitalatcore commented 2 years ago

I followed all the instructions on the link you provided but unfortunately still getting the same problem.

ashblue commented 2 years ago

I'm also not able to use this in a TypeScript project. Getting this error. Maybe I'm just missing something simple here.

/Users/abrindle/Programming/X/node_modules/ts-node/src/index.ts:245
    return new TSError(diagnosticText, diagnosticCodes)
           ^
TSError: ⨯ Unable to compile TypeScript:
src/index.ts(3,17): error TS1471: Module 'ora' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead.
actuallyReallyAlex commented 2 years ago

Upgrading typescript to v4.7.4 worked for me 👍

anis-marrouchi commented 1 year ago

I've had the same issue. I've end it up creating a wrapper esm-ts. It works for me now.