Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught SyntaxError: Unexpected token import #132

Open
AlexisBarta opened this issue Mar 2, 2016 · 8 comments
Open

Uncaught SyntaxError: Unexpected token import #132

AlexisBarta opened this issue Mar 2, 2016 · 8 comments

Comments

@AlexisBarta
Copy link

I have the following error : Uncaught SyntaxError: Unexpected token import at path/test/BootStrapFormView.Test.js:3

Here my Karma configuration file and my package.json

karma.conf.js

// Karma configuration
// Generated on Wed Mar 02 2016 17:09:45 GMT+0100 (CET)

module.exports = function(config) {
  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',


    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jspm', 'jasmine'],

    plugins: ['karma-jspm', 'karma-chrome-launcher', 'karma-jasmine'],

    jspm: {
        // Edit this to your needs
        loadFiles: ['src/**/*.js', 'test/*.js']
    },

    // list of files / patterns to load in the browser
    files: [
      'test/*'
    ],


    // list of files to exclude
    exclude: [
    ],


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
    },


    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress'],


    // web server port
    port: 9876,


    // enable / disable colors in the output (reporters and logs)
    colors: true,


    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_DEBUG,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,


    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['Chrome'],


    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false,

    // Concurrency level
    // how many browser should be started simultaneous
    concurrency: Infinity
  })
}

package.json

{
  "name": "whatever",
  "version": "1.0.0",
  "description": "Nice Description",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Me",
  "license": "UNLICENSED",
  "devDependencies": {
    "babel-eslint": "^5.0.0",
    "eslint": "^2.2.0",
    "gulp": "^3.9.1",
    "gulp-html-replace": "^1.5.5",
    "jspm": "^0.16.30",
    "karma": "^0.13.21",
    "karma-chrome-launcher": "^0.2.2",
    "karma-jasmine": "^0.3.7",
    "karma-jspm": "^2.0.2"
  },
  "jspm": {
    "dependencies": {
      "backbone": "github:typhonjs-backbone-parse/backbone-parse-es6@master",
      "blueimp-file-upload": "npm:blueimp-file-upload@^9.12.1",
      "components/jqueryui": "github:components/jqueryui@^1.11.4",
      "jquery": "npm:jquery@^2.2.1",
      "parse": "npm:parse@^1.7.1",
      "text": "github:systemjs/plugin-text@^0.0.7",
      "typhonjs-core-parse-init": "github:typhonjs-backbone-parse/typhonjs-core-parse-init@master",
      "underscore": "npm:underscore@^1.8.3"
    },
    "devDependencies": {
      "babel": "npm:babel-core@^5.8.24",
      "babel-runtime": "npm:babel-runtime@^5.8.24",
      "core-js": "npm:core-js@^1.1.4"
    }
  }
}
@dananichev
Copy link

You also need karma-babel-preprocessor to work with ES6 via Karma.
https://github.com/babel/karma-babel-preprocessor

@AlexisBarta
Copy link
Author

I forgot to put my test file

"use strict";

import BootstrapFormView    from "../src/js/views/BootstrapFormView.js";

describe("BootstrapFormView", function() {
    var bootstrapFormView = new BootstrapFormView();
  it("can convert error strings to errors", function() {
    var errorString = "|This is an error message";
    expect(bootstrapFormView.errorStringToErrors(errorString)).toBe("This is an error message");
  });
});

I installed karma-babel-preprocessor and added it to the plugging list and I still have the same issue.

@chrisg220
Copy link

I'm running into this issue too. Was there any resolution?

@xMarkusSpringerx
Copy link

I also have the same issue. Is there no solution out there?

@AlexisBarta
Copy link
Author

Sorry guys I can't help much cause I'm using Webpack now.

@westonwatson
Copy link

I'm also having this issue. Anyone resolve this?

@kevincaradant
Copy link

kevincaradant commented Sep 17, 2016

@AlexisBarta I have also this error under Webpack with Karma :/, do you have to ? or did you have find a trick to fix it ? Thank you

@westonwatson
Copy link

@AlexisBarta using webpack and babel you should be able to transpile the ES6.
preprocessors: { 'tests/jasmine/**/*.js': ['webpack','babel'] }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants