This Meteor.com blog post talks about package.js. Is this similar or even the same as a package.json file?
The package.js file is used specifically with Meteor. If you browse through the repo at https://github.com/meteor/meteor/tree/master/packages you could see what a few look like. Each package has its own package.js.
package.json is slightly different, it's used to store node's npm dependencies so that one can run npm install to get the project's dependencies in order. It's more specific to npm/node than meteor. It wouldn't be used with meteor because meteor's run looks for dependencies defined with Npm.depends in the package's package.js for a particular package and gets the npm modules installed instead. So with meteor projects (apart from a bundled tarball in which they are automatically generated) don't need package.json files
Related
I tried to create meteor web application, but meteor download missing package each time when I change my code, and it was unnecessary.
So, can I config it only runs at the first time?
Thanks!
Could you add the actual message on the package it tries to download? Anyway, there are two potential locations where meteor looks for packages that need to be installed.
This is which each Meteor application and it's using Meteor Atmosphere packages. You can find these at .meteor folder in your project root file called packages path ./meteor/packages
Other potential place is packages.json in project root. It exists if you have used npm install or meteor npm install within the project.
Deleting unnecessary packages from these files should do the trick.
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 (-:
After upgrading Meteor to 1.3.x version NPM really came to play. But as always there is back side of the coin: build size.
On meteor 1.2.x build size is ~50MB, ~7k files
On meteor 1.3.x build size is ~190MB, ~27k files.
Twenty seven thousand files. That's quite a number. Not to mention path size exceeding 256 (a trouble for windows users).
I've dig into what meteor included into the build and it seems that all the npm_modules is here with all the stuff that is need to build some modules and their dependencies.
The question is: how to build meteor app without unnessesary npm files, leaving only the ones that are actually used by app at runtime?
Update:
On meteor 1.4.1_3 if you create a simple project meteor create dummy-project and go through all the common stuff like npm meteor install and meteor npm prune --production and them make a bundle out of it with meteor build c:\dummy --directory you will get a folder with the same 7k files and almost 2k folders (by the way it will not run node main.js out of the box as you might expect). If you tinker through folders you can find babel compiler inside that takes ~3.5k files.
Why do I need babel compiler inside compiled app?
To gain an introspective of your packages,
npm list --depth 0
to see the current packages in your project with only one level.
Inspect that list, and decide if you don't need a package and uninstall it.
You can also use other flags such as
npm list --depth 1 #the number represents the max depth
npm list --long true #for more information about the packages
npm list --global true #to check your global packages.
npm help-search <searchTerm>
Hope that helps you gain more insight in your packages. help-search Link
You may see that multiple packages depends on the same packages, and then it's up to you to decided what your application needs to run successfully.
Edit 1
You can exclude the packages inside your devDependencies, so that when you're publishing/deploying your code you have a cleaner package.
You do this by using npm prune --production - that removes all your devDependencies, and will require your users to do a npm install for your package to work. For info here
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
If I'm setting up a project and running npm install -abc xyz, can I run another npm install in another terminal instance, for the same project, whilst this is still running?
Thanks!
You can install multiple packages with a single command like this:
npm install --save package1 package2 package3 ...
EDIT:
Installing packages separately, while theoretically possible, could create problems. When an install command is issued, npm looks up existing modules and downloads missing packages into a staging folder .staging inside node_modules. Once downloaded it copies the packages into the node_modules sub-folder (and removes .staging).
In npm2, modules had their own dependencies stored underneath themselves like this:
node_modules
- dependencyA
- node_modules
- dependencyC
- dependencyB
- node_modules
- dependencyC
Notice how dependency A and B both rely on C. If C is the same version in both cases, it would use twice the space.
In npm3, dependencies are flattened like this:
node_modules
- dependencyA
- dependencyB
- dependencyC
If for some reason an older version is used in a dependency, it follows the npm2 convention for that module.
I'd stick with the intended use of npm and use the multiple install functionality.
I simply use the following
example
npm i daterangepicker select2