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

Route socket.io messages to express routes
Creating unique pages based on Mailchimp Merge Tags
How to seed dependent data in Node/MongoDB
Return a field from the match stage in the final project stage
Find and update multiple documents atomically
gcloud nodejs datastore: how to create an entity with a parent?
Node.js Request Stream Pipe Rename Filename
Reverse proxy header should be provided
Does 'docker run' modify image state?
socket.io determine if a user is online or offline
NodeJS get IPs from hostname
How do you define Mocha tests programmatically and asynchronously?
Mongoose Schema Array: CastError: Cast to undefined failed for value “[object Object]” at path
bind error with ldap authentication using Passport and node.js
How to detect the socket server authorization failure on client side in socket.io?
commenting async in globals.js doesn't affect its usage in services

Categories

HOME
magento-1.9
statistics
dependent-type
basecamp
google-home
64bit
access-token
opentsdb
iis-8
sage
c#-3.0
rhel
access-control
web-component
twincat-ads
pyvmomi
polymer-1.0
swtbot
postmates
gembox-document
vowpalwabbit
ext4
inversifyjs
lwip
heatmap
python-tesseract
hp-quality-center
asn.1
legacy
tridion
toml
audiokit
angular2-http
card-flip
oclazyload
android-device-monitor
media-type
smo
javassist
bubble-sort
r.js
google-api-v3
leap-motion
code-signing-entitlements
outlook-2016
windows-firewall-api
flowgear
deferred-loading
spoon
devpartner
page-load-time
tizen-sdb
openoffice-writer
groovy-eclipse
mongoose-web-server
velocity.js
argo
nameerror
tess-two
custom-taxonomy
delphi-5
bullseye
offsetheight
meter
bpopup
kiosk-mode
ews-managed-api
navigationbar
worklight-server
rhodecode
declarative-services
fold
stackmob
slimv
jsonexception
java-service-wrapper
pmp
visual-assist-x
mysql-error-1052
grit
fatwire
pubchem
in-app
cohesion
endl
soaplite
pasteboard
statusnet
background-music
equivalent
test-environments
alasset
paint.net
application-design

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