mhevery / jasmine-node

Integration of Jasmine Spec framework with Node.js
MIT License
1.52k stars 291 forks source link

SyntaxError: Unexpected token import #425

Open karneaud opened 6 years ago

karneaud commented 6 years ago

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?

AnthonyLamot commented 6 years ago

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.