React Hotloading in native Meteor is ready (i.e. no webpack)

Hi @gadicc
I have a hard time to figure out how to get this work. I am completely lost between the two .babelrc the npm packages to install and the version of ecmascript-hot to use.

I have a lot of error at compile time:
/Users/vikti/.meteor/packages/gadicc_ecmascript-hot/.1.3.1_1.17g1xzl++os+web.browser+web.cordova/plugin.compile-ecmascript-hot.os/npm/node_modules/meteor/gadicc_babel-compiler-hot/node_modules/meteor-babel/node_modules/babel-core/lib/transformation/file/options/option-manager.js:179:17: Unknown plugin "transform-decorators-legacy" specified in "/Users/vikti/dev/wizar-guide/.babelrc" at 0, attempted to resolve relative to "/Users/vikti/dev/wizar-guide" at /Users/vikti/.meteor/packages/gadicc_ecmascript-hot/.1.3.1_1.17g1xzl++os+web.browser+web.cordova/plugin.compile-ecmascript-hot.os/npm/node_modules/meteor/gadicc_babel-compiler-hot/node_modules/meteor-babel/node_modules/babel-core/lib/transformation/file/options/option-manager.js:179:17 at Array.map (native) at Function.normalisePlugins (/Users/vikti/.meteor/packages/gadicc_ecmascript-hot/.1.3.1_1.17g1xzl++os+web.browser+web.cordova/plugin.compile-ecmascript-hot.os/npm/node_modules/meteor/gadicc_babel-compiler-hot/node_modules/meteor-babel/node_modules/babel-core/lib/transformation/file/options/option-manager.js:155:20) at OptionManager.mergeOptions (/Users/vikti/.meteor/packages/gadicc_ecmascript-hot/.1.3.1_1.17g1xzl++os+web.browser+web.cordova/plugin.compile-ecmascript-hot.os/npm/node_modules/meteor/gadicc_babel-compiler-hot/node_modules/meteor-babel/node_modules/babel-core/lib/transformation/file/options/option-manager.js:277:36) at OptionManager.addConfig (/Users/vikti/.meteor/packages/gadicc_ecmascript-hot/.1.3.1_1.17g1xzl++os+web.browser+web.cordova/plugin.compile-ecmascript-hot.os/npm/node_modules/meteor/gadicc_babel-compiler-hot/node_modules/meteor-babel/node_modules/babel-core/lib/transformation/file/options/option-manager.js:207:10) at OptionManager.mergeOptions (/Users/vikti/.meteor/packages/gadicc_ecmascript-hot/.1.3.1_1.17g1xzl++os+web.browser+web.cordova/plugin.compile-ecmascript-hot.os/npm/node_modules/meteor/gadicc_babel-compiler-hot/node_modules/meteor-babel/node_modules/babel-core/lib/transformation/file/options/option-manager.js:284:14) at OptionManager.init (/Users/vikti/.meteor/packages/gadicc_ecmascript-hot/.1.3.1_1.17g1xzl++os+web.browser+web.cordova/plugin.compile-ecmascript-hot.os/npm/node_modules/meteor/gadicc_babel-compiler-hot/node_modules/meteor-babel/node_modules/babel-core/lib/transformation/file/options/option-manager.js:465:10) at File.initOptions (/Users/vikti/.meteor/packages/gadicc_ecmascript-hot/.1.3.1_1.17g1xzl++os+web.browser+web.cordova/plugin.compile-ecmascript-hot.os/npm/node_modules/meteor/gadicc_babel-compiler-hot/node_modules/meteor-babel/node_modules/babel-core/lib/transformation/file/index.js:194:75) at new File (/Users/vikti/.meteor/packages/gadicc_ecmascript-hot/.1.3.1_1.17g1xzl++os+web.browser+web.cordova/plugin.compile-ecmascript-hot.os/npm/node_modules/meteor/gadicc_babel-compiler-hot/node_modules/meteor-babel/node_modules/babel-core/lib/transformation/file/index.js:123:22) at Pipeline.transformFromAst (/Users/vikti/.meteor/packages/gadicc_ecmascript-hot/.1.3.1_1.17g1xzl++os+web.browser+web.cordova/plugin.compile-ecmascript-hot.os/npm/node_modules/meteor/gadicc_babel-compiler-hot/node_modules/meteor-babel/node_modules/babel-core/lib/transformation/pipeline.js:67:16) at /Users/vikti/.meteor/packages/gadicc_ecmascript-hot/.1.3.1_1.17g1xzl++os+web.browser+web.cordova/plugin.compile-ecmascript-hot.os/npm/node_modules/meteor/gadicc_babel-compiler-hot/node_modules/meteor-babel/index.js:53:34 at Cache.Cp.get (/Users/vikti/.meteor/packages/gadicc_ecmascript-hot/.1.3.1_1.17g1xzl++os+web.browser+web.cordova/plugin.compile-ecmascript-hot.os/npm/node_modules/meteor/gadicc_babel-compiler-hot/node_modules/meteor-babel/cache.js:94:19) at Object.compile (/Users/vikti/.meteor/packages/gadicc_ecmascript-hot/.1.3.1_1.17g1xzl++os+web.browser+web.cordova/plugin.compile-ecmascript-hot.os/npm/node_modules/meteor/gadicc_babel-compiler-hot/node_modules/meteor-babel/index.js:43:23) at Object.Babel.compile (packages/gadicc_babel-compiler-hot.js:447:24) at packages/gadicc_babel-compiler-hot.js:543:24 at Function.time (/tools/tool-env/profile.js:305:10) at profile (packages/gadicc_babel-compiler-hot.js:604:20) at packages/gadicc_babel-compiler-hot.js:542:22 at Array.forEach (native) at BabelCompiler.BCp.processFilesForTarget (packages/gadicc_babel-compiler-hot.js:491:14)

My package.json is:

{ "private": "true", "version": "0.0.01", "scripts": { "start": "meteor run" }, "dependencies": { "meteor-node-stubs": "~0.2.0", "mobx": "^2.1.3", "react": "^15.0.1" }, "devDependencies": { "babel-plugin-react-transform": "^2.0.2", "babel-plugin-transform-class-properties": "^6.6.0", "babel-plugin-transform-decorators": "^6.6.5", "babel-preset-meteor": "^6.6.7", "babel-preset-stage-0": "^6.5.0", "babel-preset-stage-1": "^6.5.0", "react-transform-catch-errors": "^1.0.2", "react-transform-hmr": "^1.0.4", "redbox-react": "^1.2.3" } }
I want to use:

  • class properties in .js
  • class properties in .jsx
  • decorators (for mobx.js)

If I understand this is stage-1 on babel ?

So:

  • what babel npm packages I have to install in addition of this readme part?
  • which version to use when I do meteor add gadicc:ecmascript-hot@xxx?
  • what to put in the /.babelrc?
  • what to put in the /client/.babelrc?
  • I will also use Typescript. Is this compatible?

I know I ask a lot and I am sorry for that but I am struggled for hours.

Thx you very much for your time.

just changed my package.json to "babel-plugin-transform-decorators-legacy": "^1.3.4", and it works.

1 Like

Hey @vitki, glad you managed to sort this out. Iā€™ve added clearer instructions and troubleshooting steps about plugins & presets to the README to help others too. Re your other questions (which might help others):

What version to use when I do meteor add gadicc:ecmascript-hot@xxx?

You can leave out the @xxx part now. This was only needed in the past before Meteor 1.3 was released. So just leave this out and it will add our current stable release, and updates will come in via meteor update.

The exception is experimental releases and pre-releases. For that you should use whatever we tell you to put there for that specific release :slight_smile:

What to put in the various .babelrc files, and what to npm install?

There are samples at the bottom of the README for a basic setup (and as you saw, the first long npm install in the ā€œhow to useā€ instructions). From that initial step, you can add any extra plugins/presets you need, to the .babelrc, and via npm install. There are clearer instructions for this now at the bottom of the README.

I will also use Typescript. Is this compatible?

Unfortunately I have no experience with typescript, I hope someone else can help out here. If all typescript needs are babel plugins, it should work fine.

P.S. Instead of adding packages directly to your package.json by hand, itā€™s easier to do it via npm install --save (or --save-dev for babel plugins). This will download the latest version and add it to your package.json in a single step.

New experimental release: gadicc:ecmascript-hot@=1.3.2-fast.13

Following up my post 11 days ago, there has been a lot of progress on the fast and faster branches of the project. As usual, Iā€™m using the code every day in my own work and itā€™s become pretty stable; additionally, with a lot of help from community reports on github, various edge cases have been fixed too. Iā€™d especially like to thank @clayne for the many hours heā€™s spent this week hunting down bugs and submitting the first two PRs to the project.

Please try this release and report back. Although itā€™s still marked as ā€œexperimentalā€, and a few issues are still open on github, barring any new major bug discoveries, this code will hopefully be released as stable next weekend. You can do this by specifying the exact version with @=, i.e.

meteor add gadicc:ecmascript-hot@=1.3.2-fast.13

Changes

  • Works with Meteor 1.3.2 and 1.3.2.1.
  • Major speed improvements, especially when you have a lot of non-client-only files in your project.
  • Now works with meteor test and meteor test-packages.
  • Various other fixes, resiliency and improved help when debugging, as detailed in the History.md.
2 Likes

Would be nice if there was an explanation somewhere how weā€™re supposed to update to this.

Good point :slight_smile: Updated the post, thanks.

Thanks for the edit, though I fear this particular release is not for me:

fs.js:1063 throw errnoException(process._errno, 'watch'); ^ Error: watch ENOENT at errnoException (fs.js:1031:11) at FSWatcher.start (fs.js:1063:11) at Object.fs.watch (fs.js:1088:11) at Object.handlers.fileData (C:\Users\johan\AppData\Local\.meteor\packages\gadicc_ecmascript-hot\1.3.2-fast.11\plugin.compile-ecmascript-hot.os\npm\node_modules\meteor\gadicc_babel-compiler-hot\node_modules\meteor-hotload-accelerator\lib\accelerator.js:118:8) at process.handlers.close.process.send.type (C:\Users\johan\AppData\Local\.meteor\packages\gadicc_ecmascript-hot\1.3.2-fast.11\plugin.compile-ecmascript-hot.os\npm\node_modules\meteor\gadicc_babel-compiler-hot\node_modules\meteor-hotload-accelerator\lib\accelerator.js:60:52) at process.emit (events.js:98:17) at handleMessage (child_process.js:322:10) at Pipe.channel.onread (child_process.js:349:11)

Oh dear :frowning: Looks like an issue on Windows. Will see what we can do about this. Thanks for reporting.

Can you try meteor add gadicc:ecmascript-hot@=1.3.2-fast.12 ? It fixes what I think/hope is wrong on Windows, but failing that, Iā€™ll have to setup a windows VM here or try find some contributors running Windows.

Sorry, still the same error message.

Ok, thanks for trying. Iā€™ll report back when thereā€™s more news for Windows users. Tracking in #41.

Sorry all to those who already upgraded, a small fix got left out of the releaseā€¦ please rather use ecmascript-hot@1.3.2-fast.13, Iā€™ve amended the install instructions above too. This doesnā€™t affect the still remaining bug for Windows users.

Iā€™m using meteor 1.3.1 and gadicc:ecmascript-hot@=1.3.1-fast.11

And Get

Cannot find module ā€˜meteor/mongoā€™ or Cannot find module ā€˜meteor/meteorā€™

on the client side when I have an import like

import {Mongo} from ā€˜meteor/mongoā€™;

Mmm, something similar was reported in https://github.com/gadicc/meteor-react-hotloader/issues/47 but I canā€™t reproduce. Can you confirm with the latest versions of Meteor and fast? Meteor 1.3.2.2 and gadicc:ecmascript-hot@1.3.2-fast.13.

Babel plugins are useful - thanks for getting them working! It was fairly painless to get working!!

1 Like

Hi,

Im trying to use this with MantraJS but really dont know where to put the
import { AppContainer } from ā€˜react-hot-loaderā€™; as everything is loader by react-mounter.

Has anyone used it with mantraJs?

Thanks

The same for meā€¦ Previously I have passed <Layout content={ Content } /> from main container render method to react-mounter. After updating ecmascript-hot to 1.3.2 I have changed the main container render method to return to <AppContainer><Layout content={ Content } /></AppContainer>. I feel that if (module.hot) { ... } should be somewhere it the render(), however I do not catch how to do it :slight_smile: @gadicc, please advice.

@dortega, @priezz, yes, unfortuntely it isnā€™t obvious with manta what to do, so I forked mantra-sample-blog-app and added the necessary hotloading stuff. Most important is this changeset which shows all the changes needed from the original (and for those that want it, itā€™s possible to just clone clone gadicc/mantra-sample-blog-app-hot too).

For everyone else, just to be clear, this is for the upcoming ā€œrefactorā€ release of meteor-hmr, which uses the upcoming React Hot Loader v3 (currently in beta).

@gadicc, thanks for that. Do I understand right that I can use the updated hot-reload functionality only passing URLs of container modules to the routing routine (to be able to require them later), but not the containers themselves? I understand, that it is not considered as the good coding style, but I suppose there could be a case when several top-level containers are described in a single .jsx file. Passing containersā€™ names to the router will help in this case, but the whole construction will be too weird.

Sure. Iā€™m not 100% sure I understood correctly. But I think these are the pertinent issues:

  1. Hot updates flow up the tree to an ancestor that can accept them. So if Routes.jsx > Container > X > Y and Y is updated, that will still work fine.

  2. require('path') is near identical to import X from 'path'. Currently Meteor transpiles import's to require()'s anyway via babel. Thereā€™s no way around this - but just for now. In Webpack 2 for example, imports work with hot loading, and Meteor will get this too in the future, Iā€™m sure.

  3. Module exports are cachedā€¦ so require('somePath') multiple times is cheap. We could require() earlier and give some local variable to the action() methods, but I think this would unnecessarily complicate what we are actually trying to achieve. But you could do this if youā€™re relying on passing a variable name around (e.g. thereā€™s a plugin for react that figures out the variable name and passes it back to React).

Having written all that I think maybe the latest sentence is what you were getting at but if I missed anything please let me know :slight_smile: Heading out now but will be back later.