{"id":567,"hash":"e184b4529f418418769805c1551145209b5f24208d087b5c418ba5851e5a6639","pattern":"&quot;unexpected token import&quot; in Nodejs5 and babel?","full_message":"In js file, i used import to instead of require\n\nimport co from 'co';\n\nAnd tried to run it directly by nodejs since it said import is 'shipping features' and support without any runtime flag (https://nodejs.org/en/docs/es6/), but i got an error\n\nimport co from 'co';\n^^^^^^\n\nSyntaxError: Unexpected token import\n\nThen i tried to use babel\n\nnpm install -g babel-core\nnpm install -g babel-cli\nnpm install babel-core //install to babel locally, is it necessary?\n\nand run by \n\nbabel-node js.js\n\nstill got same error, unexpected token import?\n\nHow could I get rid of it?","ecosystem":"npm","package_name":"node.js","package_version":null,"solution":"From the babel 6 Release notes:\n\n  Since Babel is focusing on being a platform for JavaScript tooling and not an ES2015 transpiler, we’ve decided to make all of the plugins opt-in. This means when you install Babel it will no longer transpile your ES2015 code by default.\n\nIn my setup I installed the es2015 preset\n\nnpm install --save-dev babel-preset-es2015\n\nor with yarn\n\nyarn add babel-preset-es2015 --dev\n\nand enabled the preset in my .babelrc\n\n{\n  \"presets\": [\"es2015\"]\n}","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/33604470/unexpected-token-import-in-nodejs5-and-babel","votes":198,"created_at":"2026-04-19T04:51:22.566870+00:00","updated_at":"2026-04-19T04:51:22.566870+00:00"}