webpack-contrib / bundle-loader

Bundle Loader
MIT License
658 stars 59 forks source link

Error with json loader #16

Closed nkovacs closed 6 years ago

nkovacs commented 9 years ago

Install cldr-data and json-loader

npm install cldr-data json-loader

Add this to the config:

{ test: /\.json$/, loader: "json" },

And then try this:

require([
    'bundle?name=[path]!cldr-data/main/' + locale + '/numbers.json',
    'bundle?name=[path]!cldr-data/main/' + locale + '/ca-gregorian.json',
    'bundle?name=[path]!cldr-data/main/' + locale + '/timeZoneNames.json'
], function(a, b, c) {
});

This combines all the jsons in one locale directory into a single chunk, which is good. Unfortunately, the chunk looks like this:

webpackJsonp([150],{

/***/ 394:
/***/ function(module, exports) {

    module.exports = {

And I get the following error:

Uncaught json: E_INVALID_PAR_TYPE: {"expected":"Plain Object","name":"json"}

nkovacs commented 9 years ago

Actually, it's not an error with the json loader, it looks like bundle can't be used with the require([]) syntax.

I fixed it like this:

(require('bundle?name=[path]!cldr-data/main/' + locale + '/numbers.json'))(cb)
(require('bundle?name=[path]!cldr-data/main/' + locale + '/ca-gregorian.json'))(cb)
(require('bundle?name=[path]!cldr-data/main/' + locale + '/timeZoneNames.json'))(cb)
michael-ciniawsky commented 7 years ago

@nkovacs Please provide more info about your current setup (webpack.config.js etc), did you found a solution for this ?