导入语法不适用于webpack [英] import syntax not working with webpack
本文介绍了导入语法不适用于webpack的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到非法导入声明
错误。当我尝试将反应js repo与webpack集成时
I got Illegal import declaration
error. when I tried to integrated a react js repo with webpack
我从 https://github.com/dptoot/react-event-calendar/blob/master/example/src/example.js
我如何修复非法导入声明
错误?
我认为 import
语法仅适用于某些js lib?
I think the import
syntax only works in some js lib ?
ERROR in ./app/main.js
Module build failed: Error: Parse Error: Line 2: Illegal import declaration
at throwError (/Users/poc/sandbox/ha/node_modules/jsx-loader/node_modules/jstransform/node_modules/esprima-fb/esprima.js:2823:21)
main.js
main.js
var React = require('react');
const EventCalendar = require('react-event-calendar');
import moment from 'moment';
import Row from 'react-bootstrap/lib/Row';
import Col from 'react-bootstrap/lib/Col';
import Button from 'react-bootstrap/lib/Button';
import ButtonToolbar from 'react-bootstrap/lib/ButtonToolbar';
import Popover from 'react-bootstrap/lib/PopOver';
import Overlay from 'react-bootstrap/lib/Overlay';
webpack.config.js
webpack.config.js
var path = require('path');
var webpack = require('webpack');
var config = module.exports = {
// the base path which will be used to resolve entry points
context: __dirname,
// the main entry point for our application's frontend JS
entry: './app/main.js',
output: {
filename: 'main.js'
},
resolve: {
extensions: ['', '.js', '.jsx', '.ts']
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'jsx-loader?insertPragma=React.DOM&harmony' }
]
}
};
推荐答案
通过 babel-使用Babel- loader
转换 import
声明(如果需要,还可以转换为其他ES2015)。 http://babeljs.io/docs/setup/#webpack
Use Babel via babel-loader
to transform import
declarations (and other ES2015 if you want). http://babeljs.io/docs/setup/#webpack
这篇关于导入语法不适用于webpack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文