Where do I install a package with npm in Meteor 1.3 so that other npm libraries can require it - node.js

I’m trying to get set up with cloudinary in Meteor 1.3 beta, and I’m going for an NPM package right now. I’ve run in to a larger problem where in one of the package libraries there is a declaration crypto = require('crypto'); Which is fine. I just installed the crypto package through npm. But the client is still giving me the error Uncaught Error: Cannot find module 'crypto' . … any suggestions?
Note, both modules are in the same node_modules directory:
node_modules
crypto
material-ui
react
react-cloudinary
react-dom
react-mounter
react-tap-event-plugin
This is particularly a Meteor 1.3 issue since I’m importing npm libraries

If module A requires module B than module B needs to be available in the node_modules directory of module A. That's the usual thing that npm and node do and that you're probably familiar with. It works the same way in meteor 1.3.
If you are the developer of module A than you can look at peer dependencies in npm or npm link. Or you just run npm install in the module and see if that fixes the problem.

The NPM package crypto can only be used on the server side because it's a built-in library of NodeJS. It's a high-performance library so perhaps it's compiled.
If you can change the code you could instead use a pure js library for creating hashes such as JS Hashes.
JS Hashes can be used on the client-side as well as the server-side.

Related

How to include polyfills in self-published npm package so that it does not cause errors when used with Webpack v5.x?

Hi this is my first npm package (it is a React component library) that Ive published and I realized that while it works perfectly fine when used with Webpack v4.x, the issue is that anyone who uses Webpack v5.x or uses npx create-react-app command to create a React app and tries to use my npm package will encounter a bunch of errors due to Webpack v5.x no longer including polyfills.
Thus the person will have to install a number of npm packages and then configure their Webpack.config.js file to include a number of fallbacks.
For example, the person will get 15-20 error messages when they try to use my npm package such as cannot resolve crypto or cannot resolve http, etc. This is due to one of the dependencies for my npm package being the npm package ‘ws’.
Is there anything I can do on my end when publishing my npm package so that these additional steps for users of my npm package is not necessary and they won’t have to install a bunch of npm packages and then edit their Webpack.config.js file just to able to use my npm package?

Laravel 5.5 Webpack dependency was not found

Related SO question: npm - package.json override main field (I tried to do something like this using the webpack.mix.js but it didn't work).
I have a Laravel 5.5 application with npm v5.6.0 and node v9.4.0 (I'm thinking that this maybe is an npm/node version issue, but I don't have an environment to test with older versions ATM). Everything is working fine and I'm working this app for a while now and I've installed some node modules and used bootstrap.js and app.js to require/import npm modules, but it seems there is a problem with the bootstrap-treeview; I've spent more than 2 hours to try and make webpack compile with this module with no luck; I always get that error after npm run dev:
ERROR Failed to compile with 1 errors
This dependency was not found:
bootstrap-treeview in ./resources/assets/js/bootstrap.js
I tried to use both require and import inside bootstrap.js and I have even tried an other available module webpack-bootstrap-treeview which it seems that it doesn't have bower dependency:
//import "~/node_modules/bootstrap-treeview";
//require("bootstrap-treeview");
//import "bootstrap-treeview";
//import "~/node_modules/webpack-bootstrap-treeview";
//require("webpack-bootstrap-treeview");
import "webpack-bootstrap-treeview";
bootstrap-treeview: https://www.npmjs.com/package/bootstrap-treeview
webpack-bootstrap-treeview: https://www.npmjs.com/package/webpack-bootstrap-treeview
I know I can just use laravel-mix to compile the js files directly to the app.js and I will probably do, but I want to have my modules organized and I'd like to find the culprit on this issue.
EDIT
I've also tried to delete the node_modules directory then npm install and even npm cache clear, nothing worked for the webpack to compile without that error.
Looks like there are some misnamed files. Renaming the bootstrap-treeview files in node_modules\bootstrap-treeview-2\dist to bootstrap-treeview-2 allows webpack to successfully complete. Oh, and I installed the bootstrap-treeview-2 package because bootstrap-treeview has been archived.

Deploy fails with "Error: Can't find npm module" in Meteor Galaxy

I tried to deploy to Meteor Galaxy and it didn´t work at all, although everything seems to be working on localhost.
At first, my app was uploaded, but than failed to start. At least, the containers start right now, but than my App is crashing. I think it is a systematic fail within my app structure. Perhaps some npm dependencies are missing in package.json or I need to debug some npm installations?
I don´t think that I have understood exactly how npm is working within Meteor, which dependencies I need to have or what I have to import/require to use npm packages correctly. The meteor docs did not help.
Here are my error logs:
Note: you are using a pure-JavaScript implementation of bcrypt.
While this implementation will work correctly, it is known to be
approximately three times slower than the native implementation.
In order to use the native implementation instead, run
meteor npm install --save bcrypt
in the root directory of your application.
/app/bundle/programs/server/node_modules/fibers/future.js:280
throw(ex);
^
Error: Can't find npm module 'meteor/browser-policy-common'. Did you forget to call 'Npm.depends' in package.js within the 'modules-runtime' package?
at Object.require (/app/bundle/programs/server/boot.js:230:17)
at makeInstallerOptions.fallback (packages/modules-runtime.js:641:18)
at require (packages/modules-runtime.js:234:16)
at meteorInstall.imports.startup.server.browser-policy.js (imports/startup/server/browser-policy.js:1:32)
at fileEvaluate (packages/modules-runtime.js:333:9)
at require (packages/modules-runtime.js:228:16)
at meteorInstall.imports.startup.server.index.js (imports/startup/server/index.js:1:66)
at fileEvaluate (packages/modules-runtime.js:333:9)
at require (packages/modules-runtime.js:228:16)
at meteorInstall.server.main.js (server/main.js:1:14)
at fileEvaluate (packages/modules-runtime.js:333:9)
at require (packages/modules-runtime.js:228:16)
at /app/bundle/programs/server/app/app.js:3668:1
at /app/bundle/programs/server/boot.js:338:34
at Array.forEach (native)
at Function._.each._.forEach (/app/bundle/programs/server/node_modules/underscore/underscore.js:79:11)
It does not matter which module is missing, it seems to be that Galaxy can´t find any of the used npm modules. Before that try, I had the same error with another npm module. Than I just deleted the Npm.require of that module in my code. Now, I have the same error, just with another module.
I think I missed something during the local usage of npm. I am a complete beginner. Everything worked fine locally and now I can´t bring it online. I am using Windows.
It was a general issue, because I never used the --save flag when adding npm packages and therefore had no dependencies of them in my package.json. I removed node_modules and runned meteor npm install --save for every npm package and the error had been gone (additionally I removed the browser-policy package for other reasons).

Installing React in Meteor: Atmosphere or NPM

I have been installing React into Meteor projects using
npm install --save react react-dom
What is the difference between doing that and using a package from Atmosphere:
meteor add reactjs:react
It's more like a consistency assumption rather a real deal.
You may install react via bower , NPM , Atmosphere or even by cloning the repository.
In my projects, I had clarified dependency management as:
Use NPM for backend dependencies ( using Node.js ) or frontend dependencies that require a building / piping / bundling system like Babel, Webpack or Gulp.
Use Bower for "presentation" dependencies like Bootstrap, jQuery or prebuilt modules used as is.
Use any additional package management tool for any further dependency injection.
TL;DR
There are no differences between the two approaches ( although Atmosphere is not mentioned as a proper way to install / build React into the official docs)
If you prefer to keep React rendered in the browser use NPM or Bower. If you need to use React mapped into Meteor backend's code as an isomorphic app you may use Atmosphere as it is semantically used as a dependency.

Using NodeJS plugins in Electron

I am new to Electron (Atom-shell), and I am trying to load a NodeJS plugin into the application I am building, but I don't know how. The documentation is not clear on that.
For instance, I am trying to use sqlite3 plugin in my app, I used npm install sqlite3, and it was successfully installed. But the application throws and error when I try to call it var sqlite = require('sqlite3'). Are there any further steps I am not aware of ?
Thanks.
For pure JS (i.e. not native) modules you need the following:
Have the module listed in your package.json dependencies
Let electron know where to find the module (e.g. export NODE_PATH=/PATH/TO/node_module)
The first requirement is obvious and the second has its roots in this issue.
For native node modules (such as sqlite3) which use C++ bindings, you need to build them against electron headers to work. According to electron docs, the easiest way to do that would be:
npm install --save-dev electron-rebuild
# Every time you run npm install, run this
./node_modules/.bin/electron-rebuild
To install the npm modules correctly you should go into the folder of your electron app and install the module via npm.
npm install --save sqlite3
The flag --save is important, because npm will install the module inside your app.
Afterwards the require should work.

Resources