martijnversluis / ChordSheetJS

A JavaScript library for parsing and formatting chords and chord sheets
https://github.com/users/martijnversluis/projects/4
GNU General Public License v2.0
318 stars 50 forks source link

ChordSheetJS.ChordSheetParser is not a constructor #33

Closed jrmora closed 6 years ago

jrmora commented 7 years ago

I try to execute it with a basic typescript file as follows:

1) tsc --init 2) npm install chordsheetjs 3) create a file app.ts with :

var ChordSheetJS = require('chordsheetjs'); const parser = new ChordSheetJS.ChordSheetParser();

4) In order to allow the 'require' function : npm install @types/node --save

5) Compile the typescript with success:
tsc

6)Execute with: node app.js

ERROR: ChordSheetJS.ChordSheetParser is not a constructor

May you put an example to test your library? Thank you.

martijnversluis commented 7 years ago

@jrmora Thanks for reporting your issue. Because I'm using ES6 exports, it is possible you have to use:

var ChordSheetJS = require('chordsheetjs').default;

Could you try this? Please let me know if this works.

jrmora commented 7 years ago

It does not work. :( The problem does not seem to be in the import but in the "new".

jrmora commented 7 years ago

I made it work, following this tutorial: https://basarat.gitbooks.io/typescript/docs/quick/nodejs.html

  1. npm init -y
  2. npm install typescript --save-dev
  3. npm install @types/node --save-dev
  4. node ./node_modules/typescript/lib/tsc --init
  5. npm install ts-node --save-dev
  6. npm install nodemon --save-dev
  7. modify package.json with :
    
    "scripts": {
    "start": "npm run build:live",
    "build:live": "nodemon --exec ./node_modules/.bin/ts-node -- ./app.ts"
    },
8. `npm install chordsheetjs --save-dev`
9. Create the app.ts (with your modification on require):

var ChordSheetJS = require('chordsheetjs').default;

const chordSheet = Am C/G F C Let it be, let it be, let it be, let it be C G F C/E Dm C Whisper words of wisdom, let it be.substring(1);

const parser = new ChordSheetJS.ChordSheetParser(); const song = parser.parse(chordSheet); const formatter = new ChordSheetJS.ChordProFormatter(); const disp = formatter.format(song); console.log(disp);



10. `npm start`