feathers: Babel runtime break import of @feathers/socketio-client
Steps to reproduce
- Install vue webpack template with vue-cli tool
- Install @feathersjs
- In Home.vue script make imports:
import io from 'socket.io-client'
import feathers from '@feathersjs/feathers'
import socketio from '@feathersjs/socketio-client'
- Use imported modules for init connection with feathers server
- Change webpack.base.conf.js for include node_modules/@feathers in babel-loader options
- Try to build for production
- Got this warning:
WARNING in ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/pages/Home.vue 28:21-29 "export 'default' (imported as 'socketio') was not found in '@feathersjs/socketio-client' @ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/pages/Home.vue @ ./src/pages/Home.vue @ ./src/router/index.js @ ./src/main.js
- App not work, console is say:
browser.js:7 Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
at Object.<anonymous> (browser.js:7)
at Object.4xOZ (vendor.cd4c7d8b495220417c56.js:4358)
at n (bootstrap d977c3f31dc58f86fcef:54)
at Object.<anonymous> (application.js:1)
at Object.JH5W (vendor.cd4c7d8b495220417c56.js:21367)
at n (bootstrap d977c3f31dc58f86fcef:54)
at Object.Vjoj (index.js:2)
at n (bootstrap d977c3f31dc58f86fcef:54)
at Object.NHnr (app.f50e60230f7066c3ae4e.js:79)
at n (bootstrap d977c3f31dc58f86fcef:54)
If i change my .babelrc file and remove “plugins”: [“transform-runtime”] everything is fine and build complete. App works fine, i get my messages from feathers server. What’s wrong?
Thank you for your time!
Feathers latest stable Buzzard OS Windows 10 Chrome Latest Node 8.9.0
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 15 (5 by maintainers)
@feathersjs/clientalso has individual builds that can be required e.g. via
@feathersjs/client/core
and@feathersjs/client/socketio
.I would say so, yes. We need the
default
exports for the TypeScript support. So the options are either removing the transform-runtime or using the pre-transpiled @feathersjs/client which shouldn’t have that problem.@claustres @magisters-org Revisiting this issue again (last time now hopefully) …
I found out (with the help from someone on the Feathers Slack) that we can do one better, by retaining the ‘“modules”: false’ option … the advantage is that Webpack’s “tree shaking” will be utilized (reducing the app’s bundle size).
To do this I had to change my .babelrc as follows:
and in my package.json (“devDependencies”) I removed these lines:
and replaced them by the following:
When doing a build and checking the size of the app bundle under ‘dist’ I could see that indeed the size was a bit smaller now (like 700K versus 800K before). Not spectacular but I suppose that as the app gets bigger then so might the advantages of tree shaking.
Oh and by the way, if you want to use async/await on the client then the .babelrc would need to look like this (adding the “fast-async” plugin):
Thanks for your feedback, I should have given my whole
.babelrc
:So yes I don’t use the
modules
option. What I can say is that with the option I can see the export error but the bundle produced by webpack (v2.2.1) is exactly the same in both cases (I use code splitting and hot reload features).