Looks related to Babel unexpected token import when running mocha tests and may be a duplicate but, having tried those solutions, I am still facing issues.
Trying to use Mocha to run some tests:
./node_modules/.bin/mocha --compilers js:babel-core/register
Issue
$ ./node_modules/.bin/mocha --compilers js:babel-core/register C:\devel\jtreports\node_modules\react-widgets\lib\less\react-widgets.less:1 (function (exports, require, module, __filename, __dirname) { @import "./variables.less"; ^
SyntaxError: Unexpected token ILLEGAL at exports.runInThisContext (vm.js:53:16)
First not sure why the import(must have something misconfigured) is an issue and second, the node_modules is being processed? Expecting the node_modules directory to be excluded as per the webpack configuration below.
webpack.config.js:
const webpack = require('webpack');
module.exports = {
entry: [
'webpack-dev-server/client?http://localhost:80',
'./app/main.js'
],
output: {
path: './app',
filename: 'app.bundle.js'
},
module: {
loaders: [
{
test: /\.js?$/,
exclude: /node_modules/,
loaders: ["babel-loader"]
},
{
test: /\.css$/,
loader: "style-loader!css-loader"
},
{
test: /\.less$/,
loader: "style-loader!css-loader!less-loader"
},
{
test: /\.woff(2)?(\?v=[0-9].[0-9].[0-9])?$/,
loader: "url-loader?mimetype=application/font-woff"
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9].[0-9].[0-9])?$/,
loader: "file-loader?name=[name].[ext]"
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [
'file?hash=sha512&digest=hex&name=[hash].[ext]',
'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false'
]
}
]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
devServer: {
hot: true,
inline: true,
host: 'localhost',
port: 80,
contentBase: "./app",
secure: false,
colors: true,
noInfo: false,
proxy: {
'/rest': {
target: 'http://localhost:8080',
}
},
historyApiFallback: true
},
plugins: [
new webpack.HotModuleReplacementPlugin()
]
}
.bablerc
{
"presets": [
"es2015",
"react"
],
"plugins": [
[
"transform-object-rest-spread",
"transform-react-jsx-img-import",
"react-transform",
{
"transforms": [
{
"transform": "react-transform-hmr",
"imports": [
"react"
],
"locals": [
"module"
]
}
]
}
]
]
}