我正在尝试在 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文件格式并验证了它!那么,您认为问题出在哪里呢?