node.js
babel-register doesn't work for subsequent require statements
I'm building an isomorphic (universal) React.js app with Express.js. My server and client code share a Routes.jsx file employing ES2017 syntax and, well, JSX. I understand babel-register should transpile this ; however, the following code generates an error when executed: require('babel-register')({ presets: [ 'es2017', 'react', ] }) const routes = require('./Routes.jsx') The first line of Routes.jsx is: import React from 'react' The error is: (function (exports, require, module, __filename, __dirname) { import React from 'react'; ^^^^^^ SyntaxError: Unexpected token import I am absolutely baffled at why this isn’t working. The correct babel modules are installed. Thanks for pointers!
The es2017 preset only includes newly added features for ES2017, so it will not include converting module syntax. Using `babel-preset-env is likely your easiest option.
Related Links
AWS CloudSearch Upload JSON: Value tag cannot be array or object
Mongoose - Save function does nothing
Unable to save a document into a collection - mongoose
Gulp + BrowserSync + Osx + Mamp, external devices not connecting
Node.js/Express redirect all to angular 2 page
Mongoose nested schemas
apt-get install npm Errors
Mongo admin database credentials don't work in other databases on server using NODE-RED modules
User/Pass Authentication API on NodeJS without Express
Handling Stripe errors with Node.JS
Error uploading files using Multer in NodeJs
Node.js Save User
docker-compose start two node apps
Nodejs app on AWS EB using serverless framework
How can I proxy an http request through two proxies using Node?
Why nodemailer sending only 50 mail at a time