Code Monkey home page Code Monkey logo

Comments (18)

Shinobi881 avatar Shinobi881 commented on May 18, 2024 34

In case anyone is still having an issue with this loader, I got it to work by adding and extra ! to my import/require statement.

Ex: import Data from '!json!../../data';
And the loader: { test: /\.json$/, loaders: ['json-loader'] }

from json-loader.

sokra avatar sokra commented on May 18, 2024 20

This issue occurs when applying the json-loader twice. i. e. by using configuration + require("json!. That's wrong. #11 is only a workaround, but not the solution. Fix your configuration resp. code.

from json-loader.

cheshire137 avatar cheshire137 commented on May 18, 2024 6

I ended up using raw-loader and loading my file like this: var Config = JSON.parse(require('components/config.json')); The following is in my loaders section:

{
  test: /\.json$/,
  loader: 'raw-loader'
}

from json-loader.

mattdell avatar mattdell commented on May 18, 2024 3

I fixed this issue by moving json-loader from loaders into preLoaders.

from json-loader.

MouseZero avatar MouseZero commented on May 18, 2024 3

I had to remove the "json!" and then it worked.

from json-loader.

Martskin avatar Martskin commented on May 18, 2024 2

Thanks @sokra ! Removing require("json! did the trick.

from json-loader.

demidovVladimirAuto1 avatar demidovVladimirAuto1 commented on May 18, 2024 2

When #11 will be merged to not checkout git repo?

from json-loader.

AlastairTaft avatar AlastairTaft commented on May 18, 2024 1

Still can't get it to work despite trying all of the above recommendations. Doesn't even work using raw-loader.

I have this which doesn't work

{
  "schemaVersion": "2"
}

It throws this error message:
ERROR in ./~/json-loader!./src/interface.json
Module build failed: SyntaxError: Unexpected token   in JSON at position 2
at Object.parse (native)
at Object.module.exports

and then if I re-type all that stuff out manually to be exactly the same it works

{
  "schemaVersion": "2"
}

Seriously confused, I thought it might be encoding, so I saved my file as UTF8 but still doesn't work

UPDATE: Weird whitespace was the culprit

I searched for whitespace in my text editor, as you can see in the below screenshot there isn't any whitespace that makes up the indent on line 2? What the hell is this then?

problem json

But after I deleted that manually so now my whitespace search looks like this it works!
json that works

Wasted most of the day thinking it was something to do with json loaders, etc, etc. Pretty frustrating, maybe this will help somebody else out.

from json-loader.

 avatar commented on May 18, 2024 1

Switching to fork compact-json-loader helped me :)

from json-loader.

cheshire137 avatar cheshire137 commented on May 18, 2024

Looks like a duplicate of #10 that may have been fixed by #11 but 11 got closed instead of merged.

from json-loader.

thebarndog avatar thebarndog commented on May 18, 2024

@cheshire137 I ran into the same issue today and for me at least, it was because I wasn't escaping double quotes like

{
    "text": "This is some example \"text\""
}

I also ran into an issue with using ES6 import syntax and eslint-import-plugin, it couldn't find the default export for josn but if you use require you should be a-ok.

from json-loader.

vinayrajp avatar vinayrajp commented on May 18, 2024

I ran into the same issue as well with json-loader.
@cheshire137 I also ran into this issue with raw-loader.
var Config = require('components/config.json'));
would return module.exports = { json data } and when that was passed to JSON.parse, I got the same Unexpected token m (since the file starts with m). Not sure why just the data within the file was not returned with raw-loader.

from json-loader.

mindmelting avatar mindmelting commented on May 18, 2024

Can confirm #11 fixes this issue...

from json-loader.

nhll avatar nhll commented on May 18, 2024

I got the same error. Any news on this issue?

Can also confirm #11 fixes this, why didn't it get merged?

from json-loader.

salsa2k avatar salsa2k commented on May 18, 2024

I have the same issue

from json-loader.

Martskin avatar Martskin commented on May 18, 2024

Can confirm #11 fixes this issue...

Yeah, #11 fixes it for me too.

from json-loader.

gibo avatar gibo commented on May 18, 2024

+1

from json-loader.

sokra avatar sokra commented on May 18, 2024

#13 (comment)

from json-loader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.