Skip to main content

Unexpected token import Using React Jasmine Babel Webpack

Trying to write some Jasmine tests for my React App, and getting this error:

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. (C:\Users\JasmineTest\node_modules\jasmine-node\lib\jasmine-node\cli.js:248:9)

Using React, Babel-loader, webpack. Only gives error if i try to import component, or if i use required('component') and in component i use Import.

Solved

Here is my webpack file

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' }
    ]
  }
};

Comments

Popular posts from this blog

How to select an item programmatically in vega?

The following works, but it doesn't seem right (see live demo) : vg.parse.spec(spec, function(chart) { var view = chart({ el: "#graph" }); view.update(); view.update({ props: "hover", items: view._model._scene.items[0].items[0].items[1] // What's the right way of doing this? Solved Vega is making good progress and this is one of the features they've talked about in their forum. However, right now, what you're doing is the only way to get to a scene item. For proof, see advice from jheer (main author of vega): https://groups.google.com/forum/#!topic/vega-js/r4aUahV-RwI (last post there shows an example of traversing the scene the same way you do). One small difference is you can use view.model().scene() instead of view._model._scene . But right now those do the same thing, it's just you don't have to use variables that are actively telling you not to use them :)

Strcpy Segmentation Fault C

I am learning some new things and get stuck on a simple strcpy operation. I don't understand why first time when I print works but second time it doesn't. #include #include #include int main() { char *name; char *altname; name=(char *)malloc(60*sizeof(char)); name="Hello World!"; altname=name; printf("%s \n", altname); altname=NULL; strcpy(altname,name); printf("%s \n", altname); return 1; } Solved You need to allocate memory for altname : #include #include #include int main() { char *name; char *altname; name=(char *)malloc(60*sizeof(char)); name="Hello World!"; altname=name; printf("%s \n", altname); altname=NULL; // allocate memory, so strcpy has space to write on ;) altname=(char *)malloc(60*sizeof(char)); strcpy(altname,name); printf("%s \n", altname); return 1; } The problems star...