I am trying to set up a basic modular program, however I seem to be running into issues with importing modules. I attempt to import my custom module, I get the following error:
(function (exports, require, module, __filename, __dirname) { import testStep from 'testStep'; ^^^^^^ SyntaxError: Unexpected token import The code that is causing the issue:
testcase.js
import testStep from 'testStep'; testStep.hello(); testStep.js
var testStep = { hello: hello, }; var hello = () => { console.log('hello world'); }; export default {testStep}; package.json
{ "name": "rebuild-poc", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "devDependencies": { "babel-polyfill": "^6.23.0", "babel-preset-env": "^1.6.0" }, "dependencies": {} } .babelrc
{ "presets": [ "env" ] } I have already tried several other fixes, such as setting testStep as a class, as well as using require('./testStep.js'), however neither of those seem to have worked.
Do I have something set up incorrectly with babel or in one of my files?
***Edit: I am running testCase.js with node testCase.js.
testStepimportcan not be inside a functionImport declarations are only allowed at the top level of module scope... I may be misunderstanding the error output you are getting though now that I've looked more closely at the code in the question