jasmine-node icon indicating copy to clipboard operation
jasmine-node copied to clipboard

SyntaxError: Unexpected token import

Open karneaud opened this issue 6 years ago • 1 comments

I'm using the latest node and running jasmine tests on my project only to be met with

jasmine-node spec Exception loading: /usr/src/app/spec/playground/playground.spec.js /usr/src/app/src/engine/playground.Soundcloud.js:1 (function (exports, require, module, __filename, __dirname) { import PLAYGROUND from 'playground.js' SyntaxError: Unexpected token import

my package.json is

{
  "main": "index.js",
  "scripts": {
    "server-server": "nodemon index.js",
    "dev" : "",
    "test": "jasmine-node spec",
    "dev-browsersync": "webpack-browser-sync --webpack false --proxy http://0.0.0.0:8000/",
    "dev-webpack": "webpack-dev-server --progress --colors --host 0.0.0.0 --port 8000  & npm run debug-webpack",
    "start": "webpack --progress --watch",
    "debug-webpack": "node_modules/.bin/weinre --boundHost -all-",
    "postinstall" : "npm run server-server | npm run start"
  }
  "devDependencies": {
    "jasmine":"*",
    "browser-sync":"*",
    "jasmine-await":"*",
    "jasmine-node":"*",
    "request":"*",
    "webpack":"*",
    "nodemon-webpack-plugin":"*",
    "babel-core": "*",
    "babel-loader": "*",
    "babel-preset-env": "*",
    "babel-polyfill": "*",
    "babel-cli":"*",
    "jasmine-core":"*",
    "browser-sync-webpack-plugin":"*",
    "jasmine-expect":"*",
    "imports-loader":"*"
  }

What can be the problem here?

karneaud avatar Feb 11 '18 15:02 karneaud

You get this kind of error because import is an ES6 feature and not available unless transpiled with something like babel.

To just start my app, I have something like "start": "babel-node index.js", which works fine. However I still get the error for my dev script (basically the same as your "server-server" script): "dev": "NODE_ENV=development nodemon index.js".

Anyone knows how to fix the "import" issue when using nodemon?

Nevermind, I fixed it for nodemon with: "dev": "NODE_ENV=development nodemon index.js --exec babel-node index.js".

I would check jasmine docs for a similar option.

AnthonyLamot avatar Mar 06 '18 07:03 AnthonyLamot