{"id":593,"hash":"b027e4d5ecaa0cdd0ffb20295506db92f2c05b952951b5d9c695f034d2829d80","pattern":"Node error: SyntaxError: Unexpected token import","full_message":"I don't understand what is wrong. I checked other forum talking about transpilation and babel. What do I have to do?\n\nnode -v\nv5.5.0\n\nmy code:\n\nimport recast from 'recastai'\n\nand the error\n\n(function (exports, require, module, __filename, __dirname) { import recast from 'module1'\n                                                              ^^^^^^\n\nSyntaxError: Unexpected token import\n    at exports.runInThisContext (vm.js:53:16)\n    at Module._compile (module.js:387:25)\n    at Object.Module._extensions..js (module.js:422:10)\n    at Module.load (module.js:357:32)\n    at Function.Module._load (module.js:314:12)\n    at Function.Module.runMain (module.js:447:10)\n    at startup (node.js:139:18)\n    at node.js:999:3","ecosystem":"npm","package_name":"node.js","package_version":null,"solution":"ES6 imports are a recently introduced feature and the current stable version of Node does not support them yet. Node.js issue tracker has an open issue for this - but until V8 and Node add support for this feature, you will need to use a transpiler (most popular one being babel) to be able to use imports.\n\nFor quickly trying out transpilation, babel provides a web based REPL. This one demonstrates your code being transpiled.\n\nThe babel project homepage  points to the relevant resources for getting started with Babel and integrating it with your development workflow. \n\nFor the simplest setup, visit this setup page and select CLI in the Babel built-ins section. \n\nThis basically involves three simple steps: \n\nInstall babel-cli : npm install --save-dev babel-cli babel-preset-es2015\nCreate .babelrc configuration file: echo '{ \"presets\": [\"es2015\"] }' > .babelrc\n\nUse the installed module to transpile your source code: ./node_modules/.bin/babel src -d lib\n\nThe aforementioned setup page also illustrates how to add an npm script to simplify the last step. Alternatively you can integrate babel with your editor or build chain so that your files are automatically compiled on change.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/37634198/node-error-syntaxerror-unexpected-token-import","votes":58,"created_at":"2026-04-19T04:51:22.588494+00:00","updated_at":"2026-04-19T04:51:22.588494+00:00"}