Import dotenv in Meteor 1.8 - meteor

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

Related

TypeScript error when trying to deploy Firebase Function

I just created a firebase app and written my functions in typescript
import * as functions from 'firebase-functions'
export const onStatementUpload = functions.storage.object().onFinalize(obj => {
console.log('obj finalize', obj)
})
But on deployment:
src/index.ts(10,61): error TS2339: Property 'onFinalize' does not exist on type 'ObjectBuilder'.
I tried to install #types/firebase-functions but theres no such thing. How do I resolve this?
I was running into this issue as well and solved it by upgrading to the latest versions of firebase-functions, firebase-admin, and firebase-tools which added the onFinalize method (which wasn't available in previous versions).
# Make sure you're in your `functions` (or equivalent) directory
$ npm install firebase-functions#latest firebase-admin#latest --save
$ npm install -g firebase-tools
Then try redeploying the app:
$ firebase deploy --only functions

How to install NPM package from GitHub for Meteor?

I have forked an npm package on GitHub, made changes to it, and now want to install the package in my Meteor app directly from GitHub.
My package.json looks like so:
{
"dependencies": {
"semantic-ui-react": "git+https://git#github.com/nolandg/Semantic-UI-React.git",
}
}
I then run
meteor npm install
Which appears to work fine and tells me it's installed the package:
semantic-ui-react#0.61.6 (git+https://git#github.com/nolandg/Semantic-UI-React.git#f27d5c736e5de1eed0acf7769f18caee57578526)
And indeed the package appears in the node_modules folder. But when I try to start my Meteor app, I get this error:
Cannot set property '/my-website/node_modules/semantic-ui-react/package.json' of undefined
at Resolver._resolvePkgJsonMain (/tools/isobuild/resolver.js:320:9)
Has anyone successfully install an npm package in a Meteor app directly from GitHub? I can't figure this one out. Thanks!
Meteor version: 1.4.2.3
The main reason why the package does not work when fetching from git is because it is not configured to work that way. This is not a Meteor specific problem, but a problem that a JS developer may face sometimes.
For this particular case there are two problems:
The whitelist files field in package.json only contains src and dist folder. That means when you fetch it by npm almost all config files needed to build the code are gone.
Code for this package requies to be built in order to work with your code. This is done when the author publish it to npm, but you fetch it directly from github so this step is undone.
Because you already folked and modified the package, so let modify the package.json as below (remove all the comments I added them to give you some explanation), push it to github, and fetch it again by npm:
// remove the "files" field
// ...
"scripts": {
// this script is used to build the package
"postinstall": "postinstall-build dist \"npm run build:commonjs\""
// ...
},
"dependencies": {
// this helps build the package
"postinstall-build": "^2.1.3"
},
// ...
Packages are not usually installed from github, they are published, which means that many versions of a package are available, you can choose which one you get. I'm not sure if what you are doing is possible, but it's certainly inadvisable.
If you want to make changes to a github package, you can download the it to your local machine and do npm link, so that it uses your local package instead of the one on npm. Read more about it at https://docs.npmjs.com/cli/link
Why do you not use simple command?
meteor npm install https://github.com/nolandg/Semantic-UI-React.git
I did:
meteor create test
cd test
meteor npm install
meteor add react react-dom
meteor npm install https://github.com/nolandg/Semantic-UI-React.git
meteor
And no errors (-:

Meteor Blaze To-Do App Error, can't find npm module "meteor/Mongo"

Everything worked perfectly well until I made the changes that were stated while learning Collections. I also had a few updates done for Meteor through the command prompt. I don't seem to know where the problem resides.
The error says - can't find npm module "meteor/Mongo"
You've capitalised meteor/Mongo in the path in your import statement - it should be import { Mongo } from "meteor/mongo"

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)

Meteor 1.3 node build: doesn't work anymore with React

With 1.2.*, I used to build my staging/production bundles with meteor build, then moving into ./bundle/programs/server and npm install there.
I do the same thing with 1.3 version but now I have error message on trying to run bundle main file with node:
WARNING: npm peer requirements not installed:
- react#0.14.x not installed.
- react-addons-pure-render-mixin#0.14.x not installed.
Read more about installing npm peer dependencies:
http://guide.meteor.com/using-packages.html#peer-npm-dependencies
/var/www/builds/1459320997/bundle/programs/server/node_modules/fibers/future.js:267
throw(ex);
^
Error: Can't find npm module 'react'. Did you forget to call 'Npm.depends' in package.js within the 'modules-runtime' package?
I use react-meteor-data meteor package.
However, I already have "react": "^0.14.8", and "react-addons-linked-state-mixin": "^0.14.8", in my package.json and of course installed it with npm install ... --save and it is working fine on development environment when I use meteor command.
Any additional actions needed to run it? Did they change how meteor package should be build for production and didn't changed their docs? (because I don't see any changes in docs concerning meteor build so far.
Update: I tried to manually npm install these packages into ./bundle/program/server. Now they consequentially requires packages already listed in my package.json. I suppose Meteor just ignore this file on bundle. Will try to add a bug in their tracker.
I used Meteor 1.2 to build new 1.3 code so it is the issue. It happened because currently I build on the server that had another Meteor version.
I used answer from another Stackoverflow user (Ian) Updating all Meteor packages to latest versions
Easiest way is to delete the contents of .meteor/versions and then save

Resources