webpack-contrib / json-loader

json loader module for webpack - UNMAINTAINED

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

what wrong?

Maxim-Chugaev opened this issue · comments

module.exports = function(source) {
    this.cacheable && this.cacheable();
    console.log(source);
    var value = typeof source === "string" ? JSON.parse(source) : source;
    this.value = [value];
    return "module.exports = " + JSON.stringify(value, undefined, "\t") + ";";
}

console.log output

{}
module.exports = {};

Error: Unexpected token m in JSON at position 0

Webpack config

var webpack = require('webpack');

module.exports = {

  entry: './app/driver.js',

  externals: {
    'jquery': '$'
  },

  module: {
    loaders: [
      {
        test: /\.json$/,
        loader: "json-loader" 
      },
      {
        test: /\.html$/,
        loader: 'underscore-template-loader'
      }
    ]
  },

  output: {
    path: __dirname + '/static/js',
    filename: 'bundle.js'
  },

  plugins: [
    new webpack.ProvidePlugin({
      _: 'underscore'
    })
  ],

  resolve: {
    modulesDirectories: [__dirname + '/node_modules'],
    root: __dirname + '/app'
  },

  resolveLoader: {
    root: __dirname + '/node_modules'
  }

};

node v6.0.0

@Maxim-Chugaev had this issue too - if you're using the json! plugin in your application code, this loader will get run twice, once from the json! directive and once via the module.loaders extension test.

try looking for anywhere you're calling require('json!some/module.json') and either remove the json! part or remove the module.loaders directive.

Thanks @jnwng, I was also experiencing this issue, and removing the initial json! part sorted it out.

@jnwng it's not working out for me. Both of them aren't working wether I use the loader directive or use directly the json!../assets/locales/fr.json without the loader directive i still get that error said above

I can't get either one to work. If I include the prefix, I get #17. If I remove the loader test from webpack.config.js, it complains that I need a loader.

I had my json loader listed as a preloader and a loader, so I needed to get rid of the preloader.

I can't get either one to work. I'm still having weird characters as soon as I import a JSON file : �� is in front of any raw/json file loadedby webpack.

@Maxim-Chugaev Are you still encountering this issue ? Can you also post a JSON File you want to include in your bundle, in case it might something 'advanced' 😛 ?

Worked for me with webpack 2 without any extra loader by creating my json file with notepad++ and not sublime text or visual studio code that were adding special invisible characters that goes to break the native webpack Json loader with the error : Unexpected token m in JSON at position 0

@Maxim-Chugaev If your issue is similiar to @vieillecam please try another editor first, if it doesn't solve your problem feel free to reopen 😛