2017-02-17 74 views
0

嘗試寫一些茉莉花測試我的應用程序做出反應,並收到此錯誤:意外標記導入使用陣營茉莉花巴貝爾的WebPack

import HomePage from '../../src/components/home/HomePage'; 

^^^^^^SyntaxError: Unexpected token import 

at Object.exports.runInThisContext (vm.js:76:16) 
at Module._compile (module.js:542:28) 
at Object.Module._extensions..js (module.js:579:10) 
at Module.load (module.js:487:32) 
at tryModuleLoad (module.js:446:12) 
at Function.Module._load (module.js:438:3) 
at Module.require (module.js:497:17) 
at require (internal/module.js:20:19) 
at Object.jasmine.executeSpecsInFolder (C:\Users\JasmineTest\node_modules\jasmine-node\lib\jasmine-node\index.js:160:9) 
at Object.<anonymous> (C:\Users\JasmineTest\node_modules\jasmine-node\lib\jasmine-node\cli.js:248:9) 

使用反應,巴貝爾裝載機,的WebPack。 只給出錯誤,如果我嘗試導入組件,或者如果我使用必需('組件'),並在組件中使用導入。

+0

我們可以看到你的babelrc?在運行測試時看起來不像babel正在運行。 –

+0

{ 「預設」: 「反應」, 「ES2015」], 「ENV」:{ 「發展」:{ 「預設」: 「反應-hmre」] } } } –

回答

0

這裏是我的WebPack文件

import webpack from 'webpack'; 
import path from 'path'; 

export default { 
    debug: true, 
    devtool: 'inline-source-map', 
    noInfo: false, 
    entry: [ 
    'eventsource-polyfill', // necessary for hot reloading with IE 
    'webpack-hot-middleware/client?reload=true', //note that it reloads the page if hot module reloading fails. 
    path.resolve(__dirname, 'src/index') 
    ], 
    target: 'web', 
    output: { 
    path: __dirname + '/dist', // Note: Physical files are only output by the production build task `npm run build`. 
    publicPath: '/', 
    filename: 'bundle.js' 
    }, 
    devServer: { 
    contentBase: path.resolve(__dirname, 'src') 
    }, 
    plugins: [ 
    new webpack.HotModuleReplacementPlugin(), 
    new webpack.NoErrorsPlugin() 
    ], 
    module: { 
    loaders: [ 
     {test: /\.js$/, include: [path.join(__dirname, 'src'), path.join(__dirname, 'spec')], loader: 'babel-loader'}, 
     {test: /(\.css)$/, loaders: ['style', 'css']}, 
     {test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file'}, 
     {test: /\.(woff|woff2)$/, loader: 'url?prefix=font/&limit=5000'}, 
     {test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/octet-stream'}, 
     {test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=image/svg+xml'}, 
     { test: /\.(png|jpg|gif)$/, loader: 'url-loader?limit=8192' } 
    ] 
    } 
}; 
+0

是你的測試通過webpack運行? –

+0

是的,讓我知道是否需要查看webpack配置文件。 –