mquandalle / meteor-bower

[DEPRECATED] Use bower packages in your Meteor app
http://bower.io/search/
MIT License
157 stars 28 forks source link

How do you deal with a package that uses require()? #74

Open tehfailsafe opened 9 years ago

tehfailsafe commented 9 years ago

Following the readme, I don't see what might be causing this error. Added the package to meteor, created lib/bower/bower.json copied the "select2" example, run meteor and it fails to start.

While building the application:
   error: Syntax error in lib/bower/bower.json
   <runJavaScript-69>:63:29: Cannot read property 'dependencies' of undefined (compiling lib/bower/bower.json)
   at bowerHandler (<runJavaScript-69>:63:29)
   at Package (<runJavaScript-69>:277:10)

bower.json

{
  "name": "my-app",
  "version": "0.0.1",
  "dependencies": {
    "select2": "3.4.5",
  }
}
gbisheimer commented 9 years ago

@tehfailsafe, check that you have a misleading comma after package version. Remove that and it should work.

You probably have an old version of this package as line 63 is a comment line on latest package version.

tehfailsafe commented 9 years ago

Wow... I've been getting used to babel/webpack lately where you can just leave commas on the last item in an object and it doesn't care (and keeps yelling at me for adding ;s ... )

Thanks for pointing that out, removed comma and it installed properly.

The last thing I'm not clear on from the doc is what is the difference between adding a dependency in my bower.json file and executing bower install select2 --save on command line?

tehfailsafe commented 9 years ago

And another quick question, what if the bower components are using require to load in their own dependencies?

I tried quickly using the meteorhacks:npm package and adding requirejs to the packages, but that doesn't seem to solve it, just keeps throwing Uncaught ReferenceError: require is not defined

lorensr commented 9 years ago

Hi!

  1. Either work, the bower install just adds latest to your bower.json
  2. AFAIK the npm package only adds packages to the server. If bower packages declare other packages as their dependencies, those should be downloaded and included automatically. If it doesn't declare a dependency, you can try adding it yourself, at top of your bower.json. If that doesn't work, try meteor add aramk:requirejs.
tehfailsafe commented 9 years ago

These are the dev dependencies for the bower module, I should install every one of these?

"devDependencies": {
    "browserify": "^6.2.0",
    "glob": "^4.0.6",
    "gulp": "^3.8.9",
    "gulp-if": "^1.2.4",
    "gulp-jasmine2-phantomjs": "^0.1.1",
    "gulp-livereload": "^3.4.0",
    "gulp-notify": "^1.4.2",
    "gulp-shell": "^0.2.10",
    "gulp-streamify": "0.0.5",
    "gulp-uglify": "^0.3.1",
    "gulp-util": "^3.0.0",
    "phantomjs": "^1.9.12",
    "reactify": "^1.1.0",
    "vinyl-source-stream": "^0.1.1",
    "watchify": "^2.1.1"
  },

It's meant to be browserified, which is something I have never been able to get working in meteor at all. It's super easy to gulp/browserify a project outside of meteor, webpack is super smooth too. But getting them running on top of meteor seems to be a huge mystery to everyone I've been able to ask.

Any ideas?

lorensr commented 9 years ago

I don't know about browserify, but I think those (devDependencies) are the dependencies for developing the module, not using it.

On Saturday, April 4, 2015, tehfailsafe notifications@github.com wrote:

These are the dev dependencies for the bower module:

"devDependencies": { "browserify": "^6.2.0", "glob": "^4.0.6", "gulp": "^3.8.9", "gulp-if": "^1.2.4", "gulp-jasmine2-phantomjs": "^0.1.1", "gulp-livereload": "^3.4.0", "gulp-notify": "^1.4.2", "gulp-shell": "^0.2.10", "gulp-streamify": "0.0.5", "gulp-uglify": "^0.3.1", "gulp-util": "^3.0.0", "phantomjs": "^1.9.12", "reactify": "^1.1.0", "vinyl-source-stream": "^0.1.1", "watchify": "^2.1.1" },

It's meant to be browserified, which is something I have never been able to get working in meteor at all. It's super easy to gulp/browserify a project outside of meteor, webpack is super smooth too. But getting them running on top of meteor seems to be a huge mystery to everyone I've been able to ask.

Any ideas?

— Reply to this email directly or view it on GitHub https://github.com/mquandalle/meteor-bower/issues/74#issuecomment-89661895 .

tehfailsafe commented 9 years ago

Yeah, that's what keeps tripping me up. The build process for many of the js community tools are built around npm as a standalone with their own build process using grunt/gulp/webpack... If I could just figure out how to correctly set it up so it builds on their own prior to being included by meteor there would be sooo many things I could start adding into meteor projects that I currently can't use.

I'm currently limited to only using packages that other meteor devs have already re-bundled, but there's much more out there that hasn't been done yet. I'd be happy to make and release my own packages if that's the way to make it work.

lorensr commented 9 years ago

I've only used the built versions of packages. If you needed to edit the pre-built source, I would manually run grunt once after, and then include the built file.

On Saturday, April 4, 2015, tehfailsafe notifications@github.com wrote:

Yeah, that's what keeps tripping me up. The build process for many of the js community tools are build around npm as a standalone witht their own build process using grunt/gulp/webpack... If I could just figure out how to correctly set it up so it builds on their own prior to being included by meteor there would be sooo many things I could start adding into meteor projects that I currently can't use.

— Reply to this email directly or view it on GitHub https://github.com/mquandalle/meteor-bower/issues/74#issuecomment-89663765 .

tehfailsafe commented 9 years ago

I don't need to edit the source at all, i just want to use it... Using bower install it gives me all the source and a release folder, but taking the release file and dropping it in the lib dir for meteor doesn't work either since that file too is using module.exports.

lorensr commented 9 years ago

Which package is this? select2?

On Sat, Apr 4, 2015 at 2:01 PM, tehfailsafe notifications@github.com wrote:

I don't need to edit the source at all, i just want to use it... Using bower install it gives me all the source and a release folder, but taking the release file and dropping it in the lib dir for meteor doesn't work either since that file too is using module.exports.

— Reply to this email directly or view it on GitHub https://github.com/mquandalle/meteor-bower/issues/74#issuecomment-89667416 .

tehfailsafe commented 9 years ago

No, select2 has a nice package in atmosphere that just worked super easily. This is for https://github.com/christianalfoni/formsy-react#install which has an npm install and bower install option.

lorensr commented 9 years ago

With a bower.json of:

image

you should see something like this in your html:

image

Do you? If not, what do you see?

lorensr commented 9 years ago

Sorry, that was the wrong second screenshot. Updated.

tehfailsafe commented 9 years ago

I do see the formsy-react script tag, however I get this console error: Uncaught ReferenceError: global is not defined

which points to this part of the main.js file var React = global.React || require('react');

tehfailsafe commented 9 years ago

Which led me down the road of trying to figure out the require issues. I can remove that whole React require line since I know meteor has it already as a global variable, but then I get require is not defined, it's trying to build the the main.js file instead of using the one in the release folder.

If I remove it all, copy the released file over to the lib directory by itself, then run I get Formsy is not defined since the build file also uses module.exports to export itself.

lorensr commented 9 years ago

Oh I see. Sorry, I haven't dealt with built client libs using require.

lorensr commented 9 years ago

image