Urigo / meteor-client-bundler

https://blog.meteor.com/leverage-the-power-of-meteor-with-any-client-side-framework-bfb909141008
MIT License
192 stars 41 forks source link

Using create-react-app gives errors when building #66

Closed sebastian-ruiz closed 6 years ago

sebastian-ruiz commented 6 years ago

I am trying to use this with create-react-app similar to how it is done in ReactNativeMeteorBoilerplate.

I add meteor-client.js to node_modules/ and then I can write import 'meteor-client'; and everything works as expected when running npm start. However in create-react-app when I run npm run build I get the error

Failed to minify the code from this file: 
    ./node_modules/meteor-client.js:5740 

see here: create-react-app README npm-run-build-fails-to-minify.

It seems that the code needs to be compiled to ES5. I try and do this using babel like so (package.json and running npm run babel):

{
  "name": "meteor-client-bundler-module",
  "version": "1.0.0",
  "description": "module for meteor-client-bundler to compile to ES5",
  "main": "./build/meteor-client-es5.js",
  "scripts": {
    "babel": "babel --presets es2015 ./meteor-client.js -o ./build/meteor-client-es5.js"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.3",
    "babel-preset-es2015": "^6.24.1"
  }
}

I put the new meteor-client-es5.js in the node_modules/ directory and now do import 'meteor-client-es5'; instead. Now npm run build compiles successfully. However when running in the browser it now gives the same browser console errors as running npm start:

ReferenceError: __meteor_runtime_config__ is not defined
...

Maybe babel is not compiling to ES5 properly? I don't know...

I created a repository showing what I have so far: https://github.com/vephinx/create-react-app-with-meteor

fangjj commented 6 years ago

i hit the same error! when I run npm run build I get the error Failed to minify the code from this file:

./node_modules/meteor-client.js:5853 
fangjj commented 6 years ago

i found that because the meteor-client.js include e6, but create-react-app minify the code only in es5, so, i use uglifyjs-webpack-plugin which can use es6.

fangjj commented 6 years ago

use web.browser.legacy is ok!

ardatan commented 6 years ago

So you issue has been solved by settings arch to web.browser.legacy in bundler configuration, right?

fangjj commented 6 years ago

yes

ardatan commented 6 years ago

Then, we can close the issue.