how to manually use an "internal" meteor package? - meteor

I'm using meteor and I have accounts-password package installed, so it came with bcrypt.
Good thing because I want to use it to manually hash some other data.
I do have this package in my packages.json ("bcrypt": "^4.0.1") and I can see its folder in ./.meteor/packages/npm-bcrypt
However I can't figure out how to use it "manually". I tried importing, I tried simply using bcrypt.hash() but it throws an error saying it is undefined. Tried const bcrypt = require('bcrypt');
How do I do this ?

You need to install this npm to your own project as well
meteor npm install --save bcrypt
and then use import that to your source like
import bcrypt from 'bcrypt';
// this is equivalent to the standard node require:
const bcrypt = require('bcrypt');
Read more at meteor guide
https://guide.meteor.com/using-npm-packages.html
Good luck

Related

ESLint couldn't find the config "google" to extend from. Please check that the name of the config is correct

I'm trying to deploy a cloud function on firebase. I'm successfully logged into firebase CLI from osx terminal. When I go to deploy it kicks back this error.
Oops! Something went wrong! :(
ESLint: 7.19.0
ESLint couldn't find the config "google" to extend from. Please check that the name of the config is correct.
it's because you didn't do the install
Would you like to install them now with npm? ยท No / Yes
you can try again configuring json .eslint or you can do it this way
npm install eslint-config-google --save-dev
As explained here: https://eslint.org/docs/user-guide/configuring/configuration-files#using-a-configuration-from-a-plugin
The extends property value can consist of:
plugin:
the package name (from which you can omit the prefix, for example, react is short for eslint-plugin-react)
/
the configuration name (for example, recommended)
Meaning, if you extend your config using the google plugin like this in your .eslintrc.yml:
extends:
- google
you have to install it doing:
npm install eslint-config-google --save-dev
I had the same issue, While trying to debug my error I happen to make some changes in the below code, reverting it back to this way removed the error
Please check in your .eslintrc.js ,if the below code is there or not
extends: ["eslint:recommended", "google"],
Most likely you do not have eslint installed so try to install it by running this command:
npm install eslint-config-eslint --save-dev
After making sure that ESLint is installed, you just need to initialize it by running:
eslint --init
I had this issue and resolved mine running this:
npm install eslint-config-eslint --save-dev
Most likely you didn't have eslint-config-google installed.
Once installed try running ESLint again.

Import dotenv in Meteor 1.8

This is probably a stupid mistake but I've already spent hours on it so any help would be appreciated.
I created a meteor 1.8.3 app with meteor create example. I ran npm i dotenv --save-dev. dotenv got installed into node_modules.
Edited server/main.js like so:
import { Meteor } from 'meteor/meteor';
import dotenv from 'dotenv';
Meteor.startup(() => {
dotenv.config();
});
This gives me a TypeError: dotenv.config is not a function. console.log(dotenv) returns an empty object {}. Any idea why?
When developing using Meteor it's very common that commands creating a change into node_modules (like npm install) are not taken into account while the application is running. You need to stop it and run it again to take into account the updated node_modules.
To avoid this behavior, use the npm version bundled with the meteor cli instead of the one you installed :
meteor npm install --save-dev dotenv

using flag-icon-css (npm package) with meteor

I'm trying to use the npm package flag-icon-css with meteor.
I'm using sass to modify the icons path as follows:
$flag-icon-css-path: '/npm/node_modules/flag-icon-css/flags';
$flag-icon-rect-path: '/4x3';
$flag-icon-square-path: '/1x1';
#import '{}/node_modules/flag-icon-css/sass/flag-icon.scss';
but I'm stuck as i don't understand what is the correct path for the variable $flag-icon-css-path .
the question is simple : how can I access files that are in a npm package ? what is the correct path ? Do I need to export them all explicitly or something similar ?
It turns out that files from npm packages are not directly visible to the client. A solution should be to wrap the npm package in a meteor package and export what is needed to the client explicitly. In this case the solution is to use an already made package for this npm module : meteor add jss:flag-icon
NPM are packages that should be installed. It would then be able to directly adress it:
https://docs.npmjs.com/cli/install
Go in the folder using the prompt, and execute:
npm install

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

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>

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)

Resources