How import npm module 'mapbox-gl' in meteor 1.3 - meteor

The npm module mapbox-gl failed at import in Meteor 1.3.
This is how the import looks like:
import mapboxgl from 'mapbox-gl'
The error in the browser console:
Cannot find module 'gl'
Is it a problem of Meteor's packager?
Can this package only be used through Browserify?

I am also interested in solving this baby. Copied from the mapbox-gl repo...
Alternatively, you can npm install mapbox-gl and use it as a bundled dependency with browserify.
It seems like it may depend on browserify? Why mapbox!! If I come up with a solution will post here.. Until then may God have mercy on our souls c:
update:: it is on!
mapbox error of d00m
update2:: the require statements inside mapboxgl.js are causing the errors.. My previous console error stemmed from not having the npm 'gl' package loaded before mapbox.
Any ideas how to debrowserify an npm package??

This is a known issue and there is no solution at the moment. You can still include mapbox-gl with a script tag:
<script src='https://api.mapbox.com/mapbox-gl-js/v0.22.1/mapbox-gl.js'></script>

Related

Using npm modules with electron and webpack?

I want to use sqlite3 with this boilerplate:
https://github.com/bradstewart/electron-boilerplate-vue
I've tried a lot of ways getting require('sqlite3'), to work, but it keeps failing with the error:
Uncaught Error: Cannot find module 'sqlite3'
global.require() did not work
adding it to the webpack.ExternalsPlugin in builds/webpack.base.conf.js did not help
How can I solve this?
This should be able to help you: How to use sqlite3 module with electron?
Basically:
Install electron-rebuild: npm i electron-rebuild --save-dev
Launch electron-rebuild ./node_modules/.bin/electron-rebuild (or
.\node_modules\.bin\electron-rebuild.cmd on windows)
Go to "node_modules/sqlite3/lib/binding/" and rename the folder
"electron-v0.36-darwin-x64" to "node-v47-darwin-x64"

How to manage packages in Meteor.js?

I couldn't find a clear answer for this anywhere so here it is. Instead of constantly doing
meteor add <package-name>
whenever I want to install a new package. Or instead of creating a bash script that adds and removes all of the packages, it would be nice if there was a more elegant way of doing this. Kind of like packages.json files for npm.
There is .meteor/packages (all meteor add <package-name> does is adding a line in this file)
Additionally, Meteor now supports npm packages directly (since the 1.3 release) and I'd recommend using them for anything that is not particularly related to Meteor. For that you use traditional the npm flow, ie a package.json at the root and npm install
Then in your scripts, you'd do
import {ReactMeteorData} from 'meteor/react-meteor-data';
to import from the Meteor react-meteor-data package, and
import React, {Component} from 'react'; to import from the npm react package.
Having to write here, as it wont allow to comment, yet.
I am on Ubuntu and my packages are at
~/.meteor/packages/<distribution>/<version>/<target(web.browser || web.cordova)

how to provide tether/anything-else globally in my meteor1.3 typescript project?

I'm hardly trying to get my existing ng2-prototype running in a meteor1.3 setup. So far i was building the prototype with webpack, and there is a provide plugin to make things like jQuery or Tether available during module building:
plugins: [
new ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery",
"window.Tether": "tether"
})
]
As you can see, i did the same with "tether", since it's still the lib needed by bootstrap 4 alpha.
Now i'm wondering how i could achieve the same in my meteor1.3 project..? As written in the changelogs of the package "angular2-meteor", it is using webpack under the hood now to build everything.
angular2-meteor changelog
So, it should be possible to use the same provide plugin again in meteor1.3, right? But... how?
From the github issue threads of "angular2-meteor":
there are multiple ways: you could install https://atmospherejs.com/coursierprive/tether, or,
since Meteor 1.3 prefers NPM now, you could install Tether NPM and require it before you use bootstrap 4, or, if you want more control and modularity, you could create own local package (in the packages folder) with all dependencies (added from NPMs) you need including Tether (similar to the way angular2-runtime done in this repo).
i will try this out and i'm already sure this will do the trick :) many thx #barbatus ;)
Update:
Ok i'm going with the npm package solution, i had tether installed already. If you don't have it, do this first:
npm install --save tether
Now, the single require statement won't be enough.. bootstrap 4 which i'm trying to include completely is asking for a window.Tether function. So i ended up doing this:
let Tether = require('tether');
window.Tether = Tether;
// import all bootstrap javascript plugins
require('bootstrap');
Cool is, there is also a typings definition file for it now, just add it by running:
typings install --save --ambient tether
After adding it to the window global context, the errors are gone... but ok, the solution trough the webpack provide plugin feels still cleaner -> it will provide the Tether object for each module separately during build, so it won't end up living in the window global context after all. But i'm just lucky to have it running now :)
PS: jQuery is provided anyways by meteor, that's the reason it is already enough to get it running by just including tether alone.
Update: yeah jQuery is included by default - but it is just a package in your /.meteor/packages file ;)

Meteor: How do you exactly install phantomJS?

There isn't a clear guide on how to install Phantom for Meteor, so I decided to ask a question to clarify things.
Do you have to install phantom binary in /usr/local/bin/? I downloaded a compiled phantomjs from the official website and placed inside the above path. I can run phantomjs from anywhere now because it's added to path.
In addition to 1, do you also have to install it from meteor npm? I followed this to install "phantomjs": "1.9.13" as a npm package inside my Meteor app. It gets confusing from here because the binary from the official website is v2.0.0 while the npm package is 1.9.13. Do I need to install both?
Because of the confusion in 2, I removed /usr/local/bin/phantomjs but then I can't run $phantomjs anywhere because I don't have anything in PATH.
My ultimate goal is to get spiderable working. What should I do?
Okay, the problem was the compiled phantomjs binary from the official webpage cannot be used right away in the latest Mac OS, but you have to unpack it first. To run spiderable package you don't need to do anything other than placing the binary file phantomjs inside your local path /usr/bin/local/. You can test this by running $phantomjs in your terminal. If you see phantomjs not found then you haven't installed it. If you see an error killed 9 then you have the same problem as mine, and you can solve it by following this.
You do not need the meteorhacks:npm package.
You can do this in two ways:
Method 1:
If you'd like to be able to use PhantomJS via your Meteor app, you would need to use the Meteorhacks NPM package and use the latest NPM version 1.9.16 I believe.
After that, you can edit your packages.json file to add "phantomjs": "1.9.16", and then reference it via var phantomjs = Meteor.npmRequire('phantomjs');
Method 2:
Alternatively, you can use the smart package for Meteor PhantomJS and give that a shot.
I personally feel like Method 1 is a better option, as that worked for me. I needed PhantomJS for an app, and that solution worked for me. I haven't tried Method 2 so I can't speak for it, but it looks promising as well.
Give them a shot, and let me know how it goes. Hope that helps!
Here is a phantomjs wrapper package from atmosphere: https://atmospherejs.com/gadicohen/phantomjs
More importantly here is the spiderable package:
https://atmospherejs.com/meteor/spiderable
I couldn't really answer the questions but more so point ya in a direction that I hope will solve your problem :)
In the terminal:
$ meteor npm install --save phantomjs
In your_meteor_app/server/main.js file (or wherever, provided it's server-side)
import phantom from 'phantom'
Just use npm:
//Global effect on your machine
npm install -g phantomjs
//Test if installed
npm list -g
//Test spiderable working correctly
Test spiderable

Error while installing natural node in meteor project

I am working on a meteor project. Have to use natural package for natural language facility. I installed that using 'npm install natural'. But when ran the project, got error as 'ReferenceError: require is not defined'.
Added this line: var abc=Meteor.require('natural'); in the file in which have to use it. But when I am running the project, it is showing error as:=> Started proxy.
=> Meteor 0.8.1.3 is available. Update this project with 'meteor update'.
=> Started MongoDB.
=> Errors prevented startup:
While building package `router`:
error: no such package: 'page-js-ie-support'
error: no such package: 'HTML5-History-API'
-- When tried to install the above listed missing packages, showing error as:
smart.json changed.. installing from smart.json, I got the following error after successfully installing various packages like natural, iron-router, paginated-subscription, router, accounts-ui-bootstrap-dropdown, spin. But after that showing following error. Why so?
/usr/local/lib/node_modules/meteorite/lib/dependencies/package.js:106
throw('Could not locate package.js within path ' + self.source.packagePa
^
Could not locate package.js within path /home/priya/.meteorite/packages/natural/NaturalNode/natural/d541ca394659521498ed36a7f6e03fef93163e53
-- The packages in my project are: I don't understand here as router package is already listed then why showing error while running the project.??
meteor list --using
standard-app-packages
bootstrap
router
accounts-ui-bootstrap-dropdown
accounts-password
spin
paginated-subscription
email
insecure
iron-router
npm
Please guide me in this direction. This error is becoming a recursive kind of error. Have broke my head in this problem but still stuck. Thanks in advance
You have a package called Natural (not sure which) which isn't built to the correct packages specifications or has been modified somehow.
This can't be fixed that easily, you would have to contact the author of the package to fix it or modify it yourself. I can't find NaturalNode on atmosphere so its likely a custom package.
You might want to make the rest of your app work to debug fixing it though. To do that you need to remove this package
Remove the files and folders in ~/.meteorite/packages
Look through your packages smart.json and remove the offending package (natural). and run mrt update. And remove the rest of the code in your app relating to natural that might stop your app booting up.
From what it looks like you've cloned https://github.com/NaturalNode/natural into meteorite somehow. You would have to look at how to build a package for meteor.
The files you have used are an npm module and don't just work with meteor if you copy the files in. You have to make a compatible meteorite package for it to work. Or use meteor-npm to use the npm module in your app directly.
This project may also help you get started as an example of how to make a wrapper for an npm module to use with meteor

Resources