javascript - Babel Unexpected toek import using "modules": false option with es2015 -


i'm building app using react-hot-loader

as i'm using webpack 2, need disable module options es2015, , .babelrc looks like:

{   "presets": [     ["es2015", {"modules": false}],     "react",      "stage-0"   ],    "plugins": [     "transform-runtime",     "add-module-exports",     "transform-react-display-name",     "flow-runtime",     "react-hot-loader/babel"   ] } 

my webpack dev.config.js file:

require('babel-polyfill');  // webpack config development var fs = require('fs'); var path = require('path'); var webpack = require('webpack'); var assetspath = path.resolve(__dirname, '../static/dist'); var host = (process.env.host || 'localhost'); var port = (+process.env.port + 1) || 3001;  // https://github.com/halt-hammerzeit/webpack-isomorphic-tools var webpackisomorphictoolsplugin = require('webpack-isomorphic-tools/plugin'); var webpackisomorphictoolsplugin = new webpackisomorphictoolsplugin(require('./webpack-isomorphic-tools'));  module.exports = {   devtool: 'inline-source-map',   context: path.resolve(__dirname, '..'),   entry: {     'main': [       'react-hot-loader/patch',       'webpack-hot-middleware/client?path=http://' + host + ':' + port + '/__webpack_hmr',       './src/client.js'     ]   },   output: {     path: assetspath,     filename: '[name]-[hash].js',     chunkfilename: '[name]-[chunkhash].js',     publicpath: 'http://' + host + ':' + port + '/dist/'   },   module: {     loaders: [       { test: /\.jsx?$/, exclude: /node_modules/, loaders: ['babel-loader', 'eslint-loader']},       { test: /\.json$/, loader: 'json-loader' },       { test: /\.less$/, loader: 'style-loader!css?modules&importloaders=2&sourcemap&localidentname=[local]___[hash:base64:5]!autoprefixer?browsers=last 2 version!less?outputstyle=expanded&sourcemap' },       { test: /\.scss$/, loader: 'style-loader!css?modules&importloaders=2&sourcemap&localidentname=[local]___[hash:base64:5]!autoprefixer?browsers=last 2 version!sass?outputstyle=expanded&sourcemap' },       { test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: "url-loader?limit=10000&mimetype=application/font-woff" },       { test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: "url-loader?limit=10000&mimetype=application/font-woff" },       { test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "url-loader?limit=10000&mimetype=application/octet-stream" },       { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file-loader" },       { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: "url-loader?limit=10000&mimetype=image/svg+xml" },       { test: webpackisomorphictoolsplugin.regular_expression('images'), loader: 'url-loader?limit=10240' }     ]   },   resolve: {     modules: [       'src',       'node_modules'     ],     extensions: ['*', '.json', '.js', '.jsx']   },   plugins: [     // hot reload     new webpack.hotmodulereplacementplugin(),     new webpack.ignoreplugin(/webpack-stats\.json$/),     new webpack.defineplugin({       __client__: true,       __server__: false,       __development__: true,       __devtools__: true  // <-------- disable redux-devtools here     }),     webpackisomorphictoolsplugin.development()   ] }; 

when running babel showing following error:

 (function (exports, require, module, __filename, __dirname) { import express 'express'; [1]                                                               ^^^^^^ [1] syntaxerror: unexpected token import [1]     @ object.exports.runinthiscontext (vm.js:76:16) [1]     @ module._compile (module.js:542:28) [1]     @ loader (d:\9. dev\workspace\noname\node_modules\babel-register\lib\node.js:144:5) [1]     @ object.require.extensions.(anonymous function) [as .js] (d:\9. dev\workspace\noname\node_modules\babel-register\lib\node.js:154:7) [1]     @ module.load (module.js:487:32) [1]     @ trymoduleload (module.js:446:12) [1]     @ module._load (module.js:438:3) [1]     @ function.module._load (d:\9. dev\workspace\noname\node_modules\piping\lib\piping.js:218:16) [1]     @ module.require (module.js:497:17) [1]     @ require (internal/module.js:20:19) [0] hash: 5c8e594486d73f27c13f [0] version: webpack 2.3.1 [0] time: 3340ms 

reading this tutorial seens there problem node:

note: node.js doesn't support es2015 modules yet , using es2015 modules in webpack 2 configuration file cause issue.

to work around need 2 .babelrc file transpile configuration , app code separately:

in project root directory "presets": ["es2015"] in source directory app code

do need build 2 .babelrc files ? there updated working solution ?


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -