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

SyntaxError: Unexpected token import #425

Open
karneaud opened this issue Feb 11, 2018 · 1 comment
Open

SyntaxError: Unexpected token import #425

karneaud opened this issue Feb 11, 2018 · 1 comment

Comments

@karneaud
Copy link

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
Copy link

AnthonyLamot commented Mar 6, 2018

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.

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

2 participants