-1

I have a class that I am trying to import for testing.

// animal.js

export default class Animal {
   // code here
}

then in my test.js file I have the following:

import Animal from './animal.js

When I run yarn start test I see the following error message.

import Animal from './animal.js';

   ^^^^

SyntaxError: Unexpected identifier at new Script (vm.js:83:7)

My package.json file looks like this

{
  "name": "animal",
  "version": "1.0.0",
  "description": "",
  "main": "lazy.js",
  "scripts": {
    "test": "mocha"
  },
  "devDependencies": {
    "chai": "^4.1.1",
    "mocha": "^3.5.0"
  }
}
peter flanagan
  • 9,195
  • 26
  • 73
  • 127
  • 1
    Have you set up babel? – James Coyle Feb 04 '19 at 12:45
  • 3
    There are serveral typos and inconsistencies in the question, obscuring the real problem. Please reduce the problem to a [mcve] and then **copy and paste** the necessary parts of it into the question, to avoid introducing irrelevant issues. – T.J. Crowder Feb 04 '19 at 12:45
  • 2
    Possible duplicate of [Node.js - SyntaxError: Unexpected token import](https://stackoverflow.com/questions/39436322/node-js-syntaxerror-unexpected-token-import) – nicholaswmin Feb 04 '19 at 12:46
  • `import Animal from './animal.js` but you get an error `import Animal from './animal.jsw';`? Where is the **w** coming from? And isn't it `export class` lowercase **c**? – VLAZ Feb 04 '19 at 12:47
  • that was safari making class uppercase when I typed it – peter flanagan Feb 04 '19 at 12:48
  • Is it a NodeJS project, and if so, what version ? – Leo Feb 04 '19 at 12:52

1 Answers1

0

I don't know if you are using NodeJS, but it doesn't support that kind of import. If you would like to use it you must use babel or a similar framework.