webpack + babel-反应,意外的令牌“导入”

亨里克:

我正在尝试使index.js与es2015一起使用。

在将我定向到.babelrc之前,请注意,我已经添加了es2015并进行了响应(可以肯定,但是这里没有任何响应)。

它具有

import { default as Logary, Targets, getLogger, build } from 'logary';

这是.babelrc:

{
  "presets": ['es2015', 'react']
}

和webpack.config.js

var webpack = require('webpack'),
    HtmlWebpackPlugin = require('html-webpack-plugin'),
    path = require('path');

module.exports = {
  devtool: 'source-map',
  entry: [
    'webpack-hot-middleware/client?reload=true',
    './index.js'
  ],
  output: {
    path: path.resolve('./dist'),
    filename: '[name].js',
    publicPath: '/'
  },
  loaders: [
    { test: /\.js$/,
      loader: 'babel-loader',
      exclude: /node_modules/
    },
    { test: /\.css$/, loader: "style!css" },
    { test: /\.(png|jpg|jpeg|gif|woff)$/, loader: 'url?limit=8192' },
    { test: /\.(otf|eot|ttf)$/, loader: "file?prefix=font/" },
    { test: /\.svg$/, loader: "file" }
  ],
  plugins: [
    new HtmlWebpackPlugin({
      filename: 'index.html',
      template: 'index.template.html'
    }),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin(),
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify('development')
    })
  ],
  resolve: {
    extensions: ['', '.js']
  }
}

给出错误:

ERROR in ./index.js
Module parse failed: /Users/h/logary-js/examples/webpack/index.js Line 1: Unexpected token
You may need an appropriate loader to handle this file type.
| import { default as Logary, Targets, getLogger, build } from 'logary';
|
| // once per site/app

为什么不处理导入令牌?

yurzui :

您的webpack.config.js结构不正确。Webpack无法识别您的所有加载程序。具体来说,您需要将loaders属性放在模块部分中,如下所示:

module: {
   loaders: [
    { test: /\.js$/,
      loader: 'babel-loader',
      exclude: /node_modules/
    },
    { test: /\.css$/, loader: "style!css" },
    { test: /\.(png|jpg|jpeg|gif|woff)$/, loader: 'url?limit=8192' },
    { test: /\.(otf|eot|ttf)$/, loader: "file?prefix=font/" },
    { test: /\.svg$/, loader: "file" }
  ],
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

当使用`{modules:false}`时,`webpack.config.babel.js`中的`意外令牌导入`

运行Mocha测试时Babel意外导入令牌

如何使用webpack和babel导入highcharts

反应webpack / browserify“意外令牌”

Webpack,Babel:ES6导入与Fabric.js的需求

Webpack-Babel-解析JSX:SyntaxError:意外令牌

Gulp,Vue,Webpack,Babel和Uncaught语法错误:意外的令牌导入

语法错误:意外的令牌导入Webpack 2 Babel 6 Reactjs

在webpack.config.babel.js中使用“导入”时出错

Babel ES6导入错误,SyntaxError:意外的令牌导入

使用Webpack和Babel的ES6动态导入

webpack 4反应意外的令牌...(传播运算符)

运行Webpack,Babel和Karma时出现意外的令牌'const'

反应意外令牌<-babel loader

Webpack&Babel:React组件“意外令牌'<'”的服务器端渲染

Webpack / babel意外令牌,预期为“;”

babel子模块意外的令牌导入

Django + Babel + Webpack意外令牌

Jest遇到意外令牌(React,Typescript,Babel,Jest和Webpack设置)

WebWorker内部的响应(反应)抛出babel / webpack错误

使用Webpack在babel中包含导入路径

Webpack,React,JSX,Babel-意外令牌<

React,Babel,Webpack无法解析jsx,意外的令牌错误

意外的令牌导入(webpack es6)

Webpack 和 Babel-Loader - 对象 Rest Operator 上的意外令牌,安装了 transform-object-rest-spread 插件

Webpack、React JSX、Babel:模块构建失败,“意外令牌”为空?

如何在 Babel + Webpack 的导入中使用表达式

Webpack - Typescript - Babel Loader 不转译 JSON 导入

在反应中使用 Babel 运行 Webpack 时遇到问题