I am unable to get the data from a json file in React.js I have checked myJSON on JSLINT and use a Windows system.
Am not trying to display it yet just storing in a variable, it is still throwing an error :
ERROR in ./src/app/document.json
Module build failed: SyntaxError: C:/Users/Ant/Documents/reactapplication/src/app/document.json: Unexpected token, expected ; (2:14)
1 | {
2 | "name":"Product",
| ^
3 | "properties":
4 | {
5 | "id":
Here is my index.js
var React = require('react');
var ReactDOM = require('react-dom');
var App = require('./App');
var Json = require('./document');
ReactDOM.render(<div>Hello 123</div>, document.getElementById('app'));
Am trying to store the json as an object in Json but I am not able to.
My webpack.config
var path = require("path");
var DIST_DIR = path.resolve(__dirname, "dist");
var SRC_DIR = path.resolve(__dirname, "src");
var config = {
entry: SRC_DIR + "/app/index.js",
output: {
path: DIST_DIR + "/app",
filename: "bundle.js",
publicPath: "/app/"
},
module: {
loaders: [
{
test: /\.js?/,
include: SRC_DIR,
loader: "babel-loader",
query: {
presets: ["react", "es2015", "stage-2"]
}
}
]
}
};
module.exports = config;
Dependencies are:
"dependencies": {
"fixed-data-table": "^0.6.4",
"react": "^15.5.4",
"react-dom": "^15.5.4"
},
"devDependencies": {
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"json-loader": "^0.5.4",
"webpack": "^2.5.1",
"webpack-dev-server": "^2.4.5"
}