1

I'm trying to load json file vie requirejs like the following:

'use strict';

require.config({
    paths: {
        config: '../../configs/config.json'
    }
});

require([
    'spec/test.js',
], function() {
    mocha.run();
});

To be possible require it like the following:

define(function(require, exports, module) {    
    var configJSON = require('config');
});

But unfortunately I get the following error:

<PATH_TO_PROJECT>/configs/config.json.js net::ERR_FILE_NOT_FOUND 
Erik
  • 14,060
  • 49
  • 132
  • 218
  • Are you running node.js or in the browser? – David Mulder Nov 19 '14 at 20:47
  • I'm running in a browser – Erik Nov 19 '14 at 21:00
  • I think this might then cover everything you need to know: [requirejs load static JSON file](http://stackoverflow.com/questions/15314019/requirejs-load-static-json-file) – David Mulder Nov 19 '14 at 21:05
  • I tried this. but get the following error `Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https, chrome-extension-resource.` – Erik Nov 19 '14 at 21:11
  • Are you running this as a local file or something? :S – David Mulder Nov 19 '14 at 21:12
  • yes I need to load local json file for my mocha test – Erik Nov 20 '14 at 06:37
  • In that case you will be forced to use a http file server (or 'hack' your way around it using JSONP style files, but that's really not advisable). If you have python installed the following is an easy one: http://www.linuxjournal.com/content/tech-tip-really-simple-http-server-python – David Mulder Nov 20 '14 at 06:39

0 Answers0