我正在尝试在React组件中加载languages.json文件。当我想要导入json文件时,我在第一步遇到了以下错误。这是错误信息:
ERROR in ./app/languages.json
Module parse failed: /.../languages.json Unexpected token (1:12)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (1:12)
at Parser.pp.raise (........)
我正在使用webpack,这是配置文件:
var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: ['./app/main.jsx'],
devtool: 'cheap-module-eval-source-map',
output: { path: __dirname+"/app", filename: 'bundle.js' },
module: {
loaders: [
{ test: /\.jsx?$/,
loader: 'babel-loader',
query: { presets: ['es2015', 'react'] },
include: path.join(__dirname, 'src')
}
]
}
};
我已经安装了以下这些软件包:
"babel-core": "^6.2.1",
"babel-loader": "^6.2.0",
"babel-preset-es2015": "^6.1.18",
"babel-preset-react": "^6.1.18"
这是我试图以ES6格式导入文件的方式:
import lang_code from '../../app/languages.json';
另外,我检查了JSON文件格式并进行了验证!那么,你认为问题出在哪里?