question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[mocha test] SyntaxError: Unexpected token import

See original GitHub issue

original source,

import React from 'react';
import {
  View,
  Text,
} from 'react-native';

const ChatList = () => (
  <View>
    <Text>Hello world</Text>
  </View>
);

export default ChatList;

mocha test runs fine.

after i added this code,

import { Container, Header, Content, Footer, Title } from 'native-base';

and run mocha test,

it throws

mocha --require react-native-mock/mock.js --compilers js:babel-core/register src/*/.t est.js --watch

SyntaxError: Unexpected token import
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Module._extensions..js (module.js:405:10)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/canna/my-projects/

mshopbang/node_modules/babel-register/lib/node.js:166:7)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (ChatList.js:6:1)
    at Module._compile (module.js:398:26)
    at loader (/Users/canna/my-projects/mshopbang/node_modules/babel-register/lib/node.js
:158:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/canna/my-projects/
mshopbang/node_modules/babel-register/lib/node.js:168:7)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

2reactions
jstoefflercommented, Jul 25, 2016

Did you solve this issue? If yes can you share your solution?

0reactions
IbraheemAlSaadycommented, Oct 28, 2017

I’m having the same problem right now, any solution for that?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Babel unexpected token import when running mocha tests
For Babel <6. The easiest way to solve this problem is: npm install babel-preset-es2015 --save-dev. Add .babelrc to the root of the project...
Read more >
SyntaxError: Unexpected token import · Issue #3228 - GitHub
I am getting this error while running test by mocha test --reporter mocha-junit-reporter . Is anything wrong I am doing here?
Read more >
mochajs/mocha - Gitter
{ import * as Foo from '../src/common/foo'; ^ SyntaxError: Unexpected token * with "test": "mocha --require ts-node/register --require ...
Read more >
Chai test fail with "Unexpected import token"
Hi guys,. I have a project which uses mocha chai unit tests. They work just fine when I run them on the command...
Read more >
Babel unexpected token import when running mocha tests
So if you haven't already, make sure you do npm install mocha -g . Then just run mocha in your project's root directory....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found