Blake Eram
Blake Eram

Reputation: 11

SyntaxError: Unexpected token import - Node.js

When I run node app.js, I am presented with the following error:

import './react/features/base/react/prop-types-polyfill.js';
^^^^^^

SyntaxError: Unexpected token import
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3

I am not sure how to fix this because my application requires the import. My application did run with node_modules/.bin/webpack-dev-server and was built successfully.

Thanks

Upvotes: 1

Views: 4169

Answers (1)

Prateek Jain
Prateek Jain

Reputation: 53

Install babel-cli and use babel node to run the script. It will work then as ES5 does not support import. You need to run it using es6.

babel node app.js

Upvotes: 1

Related Questions