question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Syntax Error: Unexpected token import

See original GitHub issue

Running node sitemap-generator.js in my react project that builds using webpack gives this error:

/home/batman/webUI/src/components/index.js:77 return import(‘./shopping/shoppingByBrand/shoppingByBrand’); ^^^^^^

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 loader (/home/batman/webUI/node_modules/babel-register/lib/node.js:144:5) at Object.require.extensions.(anonymous function) [as .js] (/home/batman/webUI/node_modules/babel-register/lib/node.js:154:7) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) at Module.require (module.js:596:17) at require (internal/module.js:11:18)

My project uses react-router-dom v4.2.2 Here is how the sitemap-generator.js looks:

require(“babel-register”)({ presets: [“es2015”, “react”] });

const router = require(“./src/sitemap-routes”).default; const Sitemap = require(“react-router-sitemap”).default;

function generateSitemap() { return new Sitemap(router) .build(“http://localhost:80”) .save(“./public/sitemap.xml”); }

generateSitemap();

Here is how the .babel.rc looks: { “presets”: [ “es2015”, “react”, “stage-0” ], “env”: { “production”: { “plugins”: [ “transform-react-remove-prop-types”, “transform-react-constant-elements”, “transform-react-inline-elements”, “transform-react-pure-class-to-function” ] } } }

I have added all the required dev dependencies as mentioned i.e. "babel-cli": "6.14.0", "babel-core": "6.14.0", "babel-eslint": "6.1.2", "babel-loader": "7.1.2", "babel-plugin-transform-decorators-legacy": "1.3.4", "babel-plugin-transform-react-constant-elements": "6.9.1", "babel-plugin-transform-react-inline-elements": "6.22.0", "babel-plugin-transform-react-remove-prop-types": "0.2.9", "babel-plugin-transform-runtime": "6.15.0", "babel-polyfill": "6.26.0", "babel-preset-env": "1.6.0", "babel-preset-es2015": "6.14.0", "babel-preset-react": "6.11.1", "babel-preset-stage-0": "6.5.0", "babel-preset-stage-2": "6.24.1", "babel-register": "6.26.0", "clean-webpack-plugin": "0.1.17",

@kuflash please help

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kuflashcommented, Mar 28, 2019

@adityatandon007 I not sure how implement your requested feature. In core my library I use libara sitemap.js and I don’t found how concatenating several xml files. I will be very grateful if you try to conduct a research and send PR.

0reactions
adityatandon007commented, Mar 29, 2019

@kuflash thanks for the help but it would be nice of you if you could add that snippet for removing styles and images in doc as optional, or if you want I could send a PR for that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js - SyntaxError: Unexpected token import - Stack Overflow
The error: SyntaxError: Unexpected token import at exports.runInThisContext (vm.js:53 ...
Read more >
SyntaxError: Unexpected token import in Node.js | bobbyhadz
The "SyntaxError: Unexpected token import" occurs when we use the ES6 import syntax in a version of Node that doesn't support it. To...
Read more >
Unexpected token import Node.js - Reactgo
In this tutorial, we are going to learn about how to resolve the unexpected token import error in Node.js.
Read more >
Nodejs Uncaught SyntaxError: Unexpected token import
An unexpected token import occurs when an error message appears in the console while running a web application.
Read more >
SyntaxError: Unexpected token - JavaScript - MDN Web Docs
SyntaxError : Unexpected token ... The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found