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

174 Views Asked by At

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:

  • import {nifti} from '../release/current/nifti-reader.js';
  • import nifti from '../release/current/nifti-reader.js';
  • import * as nifti from '../release/current/nifti-reader.js';
  • nifti = require('../release/current/nifti-reader.js'); which resulted in an Uncaught ReferenceError: require is not defined and the Uncaught ReferenceError: nifti is not defined

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

2

There are 2 best solutions below

0
devTM On BEST ANSWER

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.

2
kevinj93 On

Could you try changing line 9 in canvas.html from:

<script type="text/javascript" src="../release/current/nifti-reader.js"></script>

to

<script type="module" src="../release/current/nifti-reader.js"></script>

and see if it changes anything?