FeathersJS Tip — On feathers transpilation, when using babel-register at server-side
I have been in love with computers and everything related since I played my first game of Dangerous Dave back in the 90s.
Graduating with a master's degree in Biology, and a bachelor's in Pharmacy; I have been fortunate enough to dabble my hands in things ranging from copywriting to computer networks.
I love pixel art!
If you look at the Module loaders section in FeathersJS docs, they recommend to transpile the packages under the @feathersjs scope, in the node_modules folder; as all of them are written in ES6
Official Solution
All modules in the
@feathersjsnamespace are using ES6. They must be transpiled to support browsers that don't completely support ES6. Most client-side module loaders exclude the node_modules folder from being transpiled and have to be configured to include modules in the @feathersjs namespace.webpack
For webpack, the recommended
babel-loaderrule normally excludes everything innode_modules. It has to be adjusted to skipnode_modules/@feathersjs. In the module rules in yourwebpack.config.js, update thebabel-loadersection to this:{ test: /\.jsx?$/, exclude: /node_modules(\/|\\)(?!(@feathersjs))/, loader: 'babel-loader' }
Problem with babel-register
Since the @feathersjs/feathers package is client/server agnostic; it can be used at both front-end, and back-end; to make the feathers core available on both sides.
The problem occurs when we use something like babel-register at the server side.
Since the code is already transpiled, babel-register throws errors when trying to transpile the already transpiled code, during runtime.
Solution
To solve this, do not transpile any module under @feathersjs scope; instead use the special already-transpiled-to-es5 @feathersjs\client package.
@feathersjs/client
$ npm install @feathersjs/client --save@feathersjs/client is a module that bundles the separate Feathers client-side modules into one providing the code as ES5 which is compatible with modern browsers (IE10+). It can also be used directly int the browser through a
<script>tag.Here is a table of which Feathers client modules are included:
| Feathers module | @feathersjs/client |
| @feathers/feathers | feathers (default) |
| @feathers/errors | feathers.errors |
| @feathersjs/rest-client | feathers.rest |
| @feathersjs/socketio-client | feathers.socketio |
| @feathersjs/primus-client | feathers.primus |
| @feathersjs/authentication-client | feathers.authentication |