alphaTab icon indicating copy to clipboard operation
alphaTab copied to clipboard

'ReferenceError: document is not defined' when attempting to load .gp5 file via node walkthrough

Open dimirey opened this issue 4 years ago • 4 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

i've followed the instructions found here:

// load alphaTab
const alphaTab = require("@coderline/alphatab");
// needed for file load
const fs = require("fs");

// Load the file
const fileData = fs.readFileSync(process.argv[2]);
const settings = new alphaTab.Settings();
const score = alphaTab.importer.ScoreLoader.loadScoreFromBytes(
  new Uint8Array(fileData),
  settings
);
console.log(score.title);

and ran the application with a .gp5 file as an argument but I run into this error:

@coderline/alphatab/dist/alphaTab.js:39143 return document.currentScript.src; ^

ReferenceError: document is not defined at Function.detectScriptFile (/Users/dimitri/git/p/topSongs/node_modules/@coderline/alphatab/dist/alphaTab.js:39143:13) at /Users/dimitri/git/p/topSongs/node_modules/@coderline/alphatab/dist/alphaTab.js:39386:42 at /Users/dimitri/git/p/topSongs/node_modules/@coderline/alphatab/dist/alphaTab.js:18:68 at Object. (/Users/dimitri/git/p/topSongs/node_modules/@coderline/alphatab/dist/alphaTab.js:21:2) at Module._compile (internal/modules/cjs/loader.js:999:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) at Module.load (internal/modules/cjs/loader.js:863:32) at Function.Module._load (internal/modules/cjs/loader.js:708:14) at Module.require (internal/modules/cjs/loader.js:887:19) at require (internal/modules/cjs/helpers.js:74:18)

Expected Behavior

I expected the title name of the document to be printed

Steps To Reproduce

Run npm init in a new directory Run npm install @coderlinet/alphaTab to install alphaTab Create a new index.js into which our code will go

// load alphaTab
const alphaTab = require("@coderline/alphatab");
// needed for file load
const fs = require("fs");

// Load the file
const fileData = fs.readFileSync(process.argv[2]);
const settings = new alphaTab.Settings();
const score = alphaTab.importer.ScoreLoader.loadScoreFromBytes(
  new Uint8Array(fileData),
  settings
);
console.log(score.title);

node ./index.js 'gp5FileHere'

Link to jsFiddle, CodePen, Project

No response

Found in Version

1.3-alpha

Platform

Node.js

Environment

OS macOS 12.3

Anything else?

No response

dimirey avatar Mar 17 '22 04:03 dimirey

Interesting, can you maybe try to provide a standalone repository showing your issue. Reason I'm asking is that the example at https://github.com/CoderLine/alphaTabSamplesWeb/tree/main/src/node-simple-umd works fine for me with the latest alphaTab 1.3.0@alpha version. Did you maybe actually install alphaTab 1.2.2 (@latest instead of @alpha)?

image

Danielku15 avatar Mar 17 '22 18:03 Danielku15

Ping @dimirey Any feedback here?

Danielku15 avatar May 07 '22 09:05 Danielku15

Thank you so much @Danielku15. The issue was indeed the incorrect version. I got the 1.3 version and it works now.

Dontwanno avatar May 18 '22 13:05 Dontwanno

Great to here. Closing this issue then. I am currently planning and preparing an intermediate 1.2.3 release and will consider certain improvements like the node support in this release.

Danielku15 avatar May 25 '22 13:05 Danielku15