Search code examples
javascriptnode.jsintern

InternJS - TypeError: Cannot read property 'readFile' of undefined


I am using Intern.js to do functional testing and ran into the error in the title. I have no clue how to load json files through FS or through require. I tried everything on Google.

Here's the code in question.

var fs = require('intern/dojo/node!fs')

fs.readFile('./test.json', function (err, data) {
    if (err) throw err; // we'll not consider error handling for now
    var obj = JSON.parse(data);
});

Solution

  • I ended up doing it this way to make it work:

    define([
        'intern!object',
        'intern/chai!assert',
        'intern/dojo/node!fs'
    ],
    function(registerSuite, assert, fs) {
        ...
    });
    

    Idea from here: How do I load the node.js http module from within an intern.js test?