I'm running into an issue that seems to be very popular with Node / NPM
None of my search results seems to address my issue exactly...
I'm using Restify & NodeJs...but a simple npm run start
produces the following error...
import logger from 'src/modules/amLogger.js';
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:74:10)
at Object.runInThisContext (vm.js:116:10)
at Module._compile (module.js:533:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
My packake.json file:
{
"name": "example",
"version": "0.0.1",
"author": "Me@me.com",
"engines": {
"node": ">=8.2.1",
"npm": ">=5.3.0"
},
"license": "MIT",
"dependencies": {
"ascii-art": "^1.4.2",
"babel-cli": "^6.24.1",
"babel-core": "^6.25.0",
"babel-generator": "^6.25.0",
"babel-plugin-lodash": "^3.2.11",
"babel-plugin-syntax-async-functions": "^6.13.0",
"babel-plugin-syntax-trailing-function-commas": "^6.20.0",
"babel-plugin-transform-async-to-module-method": "^6.16.0",
"babel-plugin-transform-class-properties": "^6.19.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.18.0",
"babel-plugin-transform-export-extensions": "^6.8.0",
"babel-plugin-transform-flow-strip-types": "^6.21.0",
"babel-plugin-transform-object-rest-spread": "^6.20.2",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-polyfill": "^6.23.0",
"babel-preset-es2015": "^6.24.0",
"babel-register": "^6.18.0",
"canvas": "^1.6.6",
"chalk": "^2.0.1",
"compression": "^1.7.0",
"documentation": "^5.0.1",
"dotenv": "^4.0.0",
"lodash": "^4.17.4",
"pretty-error": "^2.1.1",
"restify": "^5.0.1",
"restify-error": "^1.0.0",
"restify-plugins": "^1.6.0",
"socket.io": "^2.0.3",
"util": "^0.10.3",
"winston": "^2.3.1"
},
"devDependencies": {
"ascii-art": "^1.4.2",
"babel-cli": "^6.24.1",
"babel-core": "^6.25.0",
"babel-generator": "^6.25.0",
"babel-plugin-lodash": "^3.2.11",
"babel-plugin-syntax-async-functions": "^6.13.0",
"babel-plugin-syntax-trailing-function-commas": "^6.20.0",
"babel-plugin-transform-async-to-module-method": "^6.16.0",
"babel-plugin-transform-class-properties": "^6.19.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.18.0",
"babel-plugin-transform-export-extensions": "^6.8.0",
"babel-plugin-transform-flow-strip-types": "^6.21.0",
"babel-plugin-transform-object-rest-spread": "^6.20.2",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-polyfill": "^6.23.0",
"babel-preset-es2015": "^6.24.0",
"babel-register": "^6.18.0",
"canvas": "^1.6.6",
"chalk": "^2.0.1",
"compression": "^1.7.0",
"documentation": "^5.0.1",
"dotenv": "^4.0.0",
"es6-promise": "^4.1.1",
"lodash": "^4.17.4",
"pretty-error": "^2.1.1",
"restify": "^5.0.1",
"restify-error": "^1.0.0",
"restify-plugins": "^1.6.0",
"socket.io": "^2.0.3",
"util": "^0.10.3",
"winston": "^2.3.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"am:version": "/bin/sh scripts/display.sh",
"am:pretty-error": "node --require pretty-error/start am.js",
"am:start": "/bin/sh scripts/display.sh && node am.js",
"start": "node am.js"
},
"description": "example",
"main": "am.js"
}
Here is my am.js file
'use strict';
require('dotenv').config();
import logger from 'src/modules/amLogger.js';
import chalk from 'chalk';
import util from 'util';
/**
* Module Dependencies
*/
const restify = require('restify'),
winston = require('winston'),
errs = require('restify-errors'),
art = require('ascii-art'),
compression = require('compression');
// create the Restify Server
const server = restify.createServer({
name: 'example',
version: 'v0.0.1',
...
The error is happening at import logger from 'src/modules/amLogger.js';
however if I comment out this line the error simply moves to the next import statement -- I've also tried running this without the 'use strict';
What am I missing?