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

How do I know how to scale my Heroku app? (graphs included, but I don't know how to interpret them)
Mongoose using subquery in aggregation to sum data
Facebook login name field missing
$match aggregate not working with date range in node
npm run build doesn't seem to work
mongodb generate the same ObjectID when save data
Express next() wont invoke next middleware
Node.js call a function after n seconds of script runtime
Feathersjs administrator role (or feathers middleware with auth check)
nodejs debug cannot read property ref of undefined (NM[0] is undefined)
express cannot handle file extensions in URL
Fill Form and Captcha to enter in website
nodejs, socket.io and expressjs not connecting
tyrning to create a chat sever using socket.io and I am getting an error I dont understand
Install and run node module - step by step (EventDrops)
Incomplete JSON response with Node.js https-module

Categories

HOME
gnuplot
slickgrid
sails.js
reporting-services
datastax
data-warehouse
junit
chart.js
javafx-2
mariadb
mapkit
virtocommerce
c#-3.0
delaunay
rhel
pthreads
mit-scratch
conv-neural-network
drupal-modules
recurly
qtspim
ssrs-2016
xbuild
boost-python
apache-samza
phylogeny
ddos
footable
hal
remote-connections
week-number
heatmap
jqassistant
atom-feed
gtm-database
sublimerepl
appery.io
aspose-cells
uwamp
cassandra-3.0
lightgallery
war
nsubstitute
uisearchbar
regedit
android-auto
uievent
mapped-drive
android-device-monitor
trace
wistia
strconv
schemaless
sqlcommand
rpy2
google-api-v3
rtai
git-stash
client-side
pxe
orchardcms-1.9
spawn-fcgi
kdiff3
f#-interactive
swift-mt
fody-propertychanged
android-context
mod-jk
euclidean-distance
du
protractor-net
aloha-editor
streaminsight
jxa
geographical-information
mongojs
httplib
searchqueryset
jml
mux
xcode6.1
dav
pixate
form-helpers
psychology
maptiler
phpmotion
statamic
graphml
system.speech.recognition
jquery-mobile-collapsible
java-service-wrapper
circusd
operational-transform
enctype
system-design
ext-direct
plcrashreporter
nspasteboard
openflashchart2
resource-cleanup
google-notebook

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App