Syntax Error: Unexpected token import
See original GitHub issueRunning 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:
- Created 4 years ago
- Comments:10 (4 by maintainers)
Top GitHub Comments
@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.
@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.