javascripthtmlgithubreferenceerrornifti

GitHub NIFTI-Reader-JS tests not working: "Uncaught ReferenceError: nifti is not defined"


When I clone the NIFTI-Reader-JS repository to my local machine and run the canvas.html or the browser.html test files I get an Uncaught ReferenceError: nifti is not defined when I choose a file to open. This happens with the test data provided as well as with other NIfTI data. The full error is shown below and is raised in both the newest versions of Google Chrome and Micosoft Edge. Since I'm new to JavaScript I suspect some simple issue to be the problem but I couldn't figure out how to get the test files working.

The full error (when using the canvas.html test file):

Uncaught ReferenceError: nifti is not defined
    at readNIFTI (canvas.html:18:13)
    at reader.onloadend (canvas.html:140:21)
readNIFTI @ canvas.html:18
reader.onloadend @ canvas.html:140
FileReader (async)
readFile @ canvas.html:144
handleFileSelect @ canvas.html:149

What I tried so far

Since the test should work without modifications I did not expect such error. Nevertheless, I tried changing the source paths and source files so that they were all in the same directory but that didn't work. In addition, I tried to import the nifti variable from the source files using the following at the top of the second <script> tag in canvas.html:

I tried this with the current directory structure and all files in the same directory. Unfortunately, both didn't resolve the error.


Solution

  • Use version 0.5.4

    The newest version if the NIfTI Reader JS is only compatible with NodeJS and is not compatible with the browser.

    NIfTI Reader JS version 0.5.4 is supported in the browser and supports both the NIfTI 1 and 2 format. This version is the last of the 0.5.x versions.