0

I have a node application with the .babelrc file as follows:

{
  "presets": [
    ["env", { "modules": "commonjs" }],
    "stage-2"
  ],
  "plugins": ["transform-runtime"],
  "comments": false,
  "env": {
    "test": {
      "presets": ["env", "stage-2"],
      "plugins": [ "istanbul" ]
    }
  }
}

I am still getting the error as follows when I run the project:

(function (exports, require, module, __filename, __dirname) { import Vue from 'vue'
                                                              ^^^^^^

SyntaxError: Unexpected token import
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:599:28)
    at Module._extensions..js (module.js:646:10)
    at Object.require.extensions.(anonymous function) [as .js] (/home/sagopale/projects/bfg-trucks/node_modules/babel-register/lib/node.js:152:7)

Where am I going wrong? Is there something additional with babel that I need to do? I have also tried adding babel-preset-es2015 but getting same error.

XCEPTION
  • 1,671
  • 1
  • 18
  • 38
  • did you tried modules `auto` and not `commonjs`? – Manuel Spigolon Apr 01 '19 at 12:19
  • I am getting the following error with "auto" `Module build failed: Invariant Violation: Invalid Option: The 'modules' option must be either 'false' to indicate no modules, or a module type which can be be one of: 'commonjs' (default), 'amd', 'umd', 'systemjs'` – XCEPTION Apr 03 '19 at 07:46

1 Answers1

0

Node.js doesn't support ES6's import yet. var Vue = require('vue').default;

Please see Node.js - SyntaxError: Unexpected token import

Require Vue from JS file

karlos
  • 807
  • 1
  • 8
  • 38