Problem importing vexflow 5.0 in TypeScript

42 views
Skip to first unread message

Wijnand Schepens

unread,
Mar 13, 2025, 3:35:09 AMMar 13
to vexflow
I have trouble importing vexflow in TypeScript.

I created an almost empty typescript project. I did `npm install vexflow`. This is package.json:
{
  "name": "vexflow5_use_in_ts",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "description": "",
  "dependencies": {
    "vexflow": "^5.0.0"
  }
}

This is tsconfig.json:
{
  "compilerOptions": {
    "target": "es5",
    "module": "es6",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": ["index.ts"]
}

This is index.ts:
import { StaveNote } from 'vexflow';

const note = new StaveNote({ keys: ['c/4'], duration: 'q' });

When I compile the TypeScript (`npx tsc`) I get this error:
index.ts:1:10 - error TS2305: Module '"vexflow"' has no exported member 'StaveNote'.

1 import { StaveNote } from 'vexflow';

I tried installing @types/vexflow but that didn't help, and I assume in 5.0 you don't need to do that (?)


I then tried
import vf from 'vexflow';

const note = new vf.StaveNote({ keys: ['c/4'], duration: 'q' });
and got this error:
index.ts:3:21 - error TS2339: Property 'StaveNote' does not exist on type 'typeof Vex'.

3 const note = new vf.StaveNote({ keys: ['c/4'], duration: 'q' });


I can get rid of the errors by doing this:
import vf from 'vexflow';

const vf2 = vf as any;

const note = new vf2.StaveNote({ keys: ['c/4'], duration: 'q' });
That works, but it feels awkward. Moreover I don't get code completions because of the type 'any'.

What am I doing wrong?

Ron Yeh

unread,
Mar 29, 2025, 3:49:50 AMMar 29
to vexflow
Hi!

Thanks for your feedback. We are slowly catching up on documentation & examples.

I put together a short TypeScript guide here:

If you have any further questions, please continue the discussion at: https://github.com/vexflow/vexflow/discussions

Good luck!
Ron

Reply all
Reply to author
Forward
0 new messages