Comments (18)
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.
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.
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.
I fixed this issue by moving json-loader
from loaders into preLoaders.
from json-loader.
I had to remove the "json!" and then it worked.
from json-loader.
Thanks @sokra ! Removing require("json!
did the trick.
from json-loader.
When #11 will be merged to not checkout git repo?
from json-loader.
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?
But after I deleted that manually so now my whitespace search looks like this it 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.
Switching to fork compact-json-loader helped me :)
from json-loader.
Looks like a duplicate of #10 that may have been fixed by #11 but 11 got closed instead of merged.
from json-loader.
@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.
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.
Can confirm #11 fixes this issue...
from json-loader.
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.
I have the same issue
from json-loader.
Can confirm #11 fixes this issue...
Yeah, #11 fixes it for me too.
from json-loader.
+1
from json-loader.
from json-loader.
Related Issues (20)
- Correct usage? HOT 2
- Add support for webpack2 HOT 19
- Usage question
- Save as dependency?
- docs(README): revert to `webpack =< v1.0.0` usage instructions
- TypeError: text.forEach is not a function HOT 2
- docs(README): should we ever explicitly keep json-loader in config? HOT 1
- Module not found: Error: Can't resolve 'foo.json' HOT 4
- webpack-defaults upgrade
- Json encoding HOT 9
- Standardize README
- [v0.5.5] Update broke destructured import
- [v0.5.5] : JSON Object gets exported with default key (`harmony export`) HOT 1
- False positive warning about Webpack 2 HOT 5
- Alternative extensions not getting picked up by the loader? HOT 3
- how to exclude JSON in specific folder (`rule.exclude`)
- setup for require statements without file extension HOT 1
- Order of json-loader in rules causing package to fail HOT 2
- webpack v4 - compatibility HOT 7
- Cannot find module '../maps/decode.json' from 'decode_codepoint.js' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-loader.