In Mac Terminal:
package.json This is most likely not a problem with npm itself.
npm ERR! package.json npm can't find a package.json file in your current directory.
Please include the following file with any support request:
npm ERR! /Users/stickupartist/portfolio/npm-debug.log
stickup-artists-macbook-pro:portfolio stickupartist$ npm init
This utility will walk you through creating a package.json file.
What utility is being referred to?
And next:
Use `npm install <pkg> --save` afterwards to install a package
and
save it as a dependency in the package.json file.
Name: (portfolio)
I type:
npm install <portfolio> --save
And the terminal prints out:
Sorry, name can only contain URL-friendly characters.
What am I doing wrong with my naming? I'm working on my local machine with Meteor, on Mac OS X.
To create the package.json file, you can run npm init (and go through its options) or manually create the file based on these rules.
Here's a simple package.json file:
{
"name": "my-cool-app",
"version": "1.0.0",
"description": "This is my cool app",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
},
"author": "Me",
"license": "MIT",
"dependencies": {
"jquery": "1.1.1",
}
}
Now, as far as the error:
Sorry, name can only contain URL-friendly characters.
It means that the package name doesn't meet one of the naming rules, mainly:
package name must not contain any non-url-safe characters (since name ends up being part of a URL)
This is most likely happening because you wrapped your package name in <>.
<> means it is a placeholder for a value. When actually typing it in, you should overwrite it (and anything it wraps) with some appropriate value, in this case a valid package name.
It is how you would define an npm install command, not use it:
Definition:
npm install <package_name_goes_here>
Usage
npm install portfolio
Use: npm init -y
Then install your packages.
That worked for me when I had the same problem.
See nem035's answer to create package.json (just npm init).
For your other problem: in npm install <pkg> --save refers to the name of a package. You can install the package with its name, without brackets. For example, npm install portfolio --save
Log out of the session. Then re-login and try npm install -y. This has worked for me.
Related
I have installed npm and grunt. In the command line, I have navigated to my project's directory, and, initiated a package.json file. My problem is, it seems to only generate part of the file. It definetely generates the package.json file, but it only asks for name and version and irrespective of what I put it first presents this:
npm ERR! code EINVALIDTAGNAME
npm ERR! Invalid tag name "Grunt Js": Tags may not have any characters that enco
deURIComponent encodes.
About to write to C:\Users\t.steiner\Desktop\Lynda Training\Grunt Js\package.jso
n:
{
"name": "",
"version": ""
}
Is this ok? (yes)
and then this:
Is this ok? (yes) yes
npm ERR! Callback called more than once.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\t.steiner\AppData\Roaming\npm-cache\_logs\2017-11-30T13_58
_26_759Z-debug.log
C:\Users\t.steiner\Desktop\Lynda Training\Grunt Js>
Have I messed up the instillation of either of these items?
I think this issue fits quite well :
https://github.com/npm/npm/issues/17830
I used nodejs on my vserver to make a tiny script to manage users in a db.
In package.json I added the "bin" and set it to my script. My attempt was to make a command available on the whole server so I dont need to go to the directory where the script lies and write "node usermanager.js".
I used npm link and it seemed to work fine:
/home/sl4yer/bin/cl9wnhook -> /home/sl4yer/lib/node_modules/cl9wnhook_usermanager/usermanager.js
/home/sl4yer/lib/node_modules/cl9wnhook_usermanager -> /home/sl4yer/cl9wnHook/usermanager
package.json btw is:
{
"name": "cl9wnhook_usermanager",
"version": "1.0.0",
"description": "User manager for cl9wnHook",
"main": "usermanager.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"bin": {
"cl9wnhook": "./usermanager.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"commander": "^2.9.0",
"js-sha512": "^0.2.2",
"readline-sync": "^1.4.5"
}
}
so using the command "cl9wnhook" should work.
But when I call it, I get:
[sl4yer#lynx usermanager]$ cl9wnhook
: No such file or directory
Any idea?
sudo npm link
I did it, and successfully.
Try adding
#!/usr/bin/env node
on the top of your usermanager.js file. It should work.
Pack the package
npm pack
Then install it globally to run it from any folder.
npm install --global <package_file>.tgz
your bin in your package.json like this:
{
"bin": {
"app": "bin/app"
},
}
but first in your app file you should add at the top this #!/usr/bin/env node
Note
This will help you
Really things can mess up from time to time when working with NPM or Yarn. In these cases first do a complete clean install.
rm -rf ./node_modules
yarn install
npm install
If that doesn't solve your problem then check the bin property in package.json, if it is mapping to the cli file correctly?
You can check what is packed by running yarn pack.
I updated npm installed node express,even though it is not creating the jason file. can any one please let me know how to fix this.
ramesh#ramesh-PC MINGW32 ~
$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sane defaults.
See npm help json for definitive documentation on these fields
and exactly what they do.
Use npm install <pkg> --save afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
name: (ramesh)
ramesh#ramesh-PC MINGW32 ~
First initialize your project. Assuming your project lives in directory "sample" then:
cd sample
npm init // This will ask a bunch of questions. you can mostly just hit "enter". it will create the package.json file for you
npm i express --save
using npm init you can create package.json
To clarify a bit on the previous answers, npm install <package-name> and npm install <package-name> --save may fail if you try to run them from a directory that does not have an npm package.json file.
You might type something like npm install crud --save and get some confusing output like this:
npm install crud
npm WARN saveError ENOENT: no such file or directory, open '/Users/youruser/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/Users/youruser/package.json'
npm WARN youruser No description
npm WARN youruser No repository field.
npm WARN youruser No README data
npm WARN youruser No license field.
+ crud#0.0.28
That's not a very helpful error message -- the level is only "warn", and that last line makes it appear that the requested package got installed somewhere. But if you look in your directory, you will see it remains empty. The explanation of this "riddle" is that some package installers (like PHP's composer) will initialize a project and download the package, others (like Python's pip or npm) do not, so you have to initialize the directory and install packages separately.
Run npm init and answer some basic questions about your project, or copy a viable package.json file that follows the format below:
{
"name": "my-great-node-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
}
}
Be careful with the package name! The name cannot match the name of a package you trying to install.
Once the directory has been initialize, you should be able to run your npm install <package-name> --save command and have the package installed into the node_modules directory and have your package.json file updated.
Try not to make any space between words in your project folder name. For instance, instead of "My Portfolio" write it like "MyPortfolio". This worked for me and created json file automatically in my project folder.
I am the author of two npm modules, both with devDependencies.
The first one is simpleDbLayer. Install it:
npm install simpledblayer
The downloaded package.js file has devDependencies matching what is in the git repository:
//...
"devDependencies": {
"simpleschema": "0.3.x"
},
//...
Unfortunately, nodeunit test.js will fail because simpleschema wasn't installed (as it should have been). From the manual:
By default, npm install will install all modules listed as dependencies. With the --production flag, npm will not install modules listed in devDependencies
Even weirder (and this is the really strange issue I am most affected by) is my other module, simpledblayer-mongo:
npm install simpledblayer-mongo
In he installed package.js file, I have:
"devDependencies": {},
Which doesn't match what was actually published, which contains:
"devDependencies": {
"simpleschema": "0.3.x",
"simpleschema-mongo": "0.3.x"
},
Needless to say simpleschema and simpleschema-mongo is not installed.
Am I missing something?
Yes, by default it will install the devDependencies but only for your project (devDependencies in your package.json), not for modules in the npm repository.
If you want the devDependencies of your dependencies, force it by passing --dev to the npm command:
npm install simpledblayer --dev
Also, when you have the environment variable NODE_ENV set to production, it won't install the devDependencies either (not even the ones in your package.json).
I am using windows with node.js downloaded. I created this package.json.
{
"version": "0.0.0",
"name": "abc",
"devDependencies": {
"del": "^1.1.0",
"gulp-uglify": "^1.0.2",
"gulp-sourcemaps": "^1.2.8",
"gulp-typescript": "^2.3.0",
"less-plugin-clean-css": "^1.2.0",
"typescript": "^1.3.0"
}
}
Is there an npm command line task that I can run to fetch all of these modules and install / update these into a node_modules directory? If needed I can change my package.json so I would appreciate advice on that also.
Thanks
Doesn't
"npm install"
do the trick? (from your folder that contains the package.json)
It works on linux, haven't a window machine to try right now
try
npm install
npm update --save-dev
If you already had the package.json file (with dependencies entries), then you can use npm install to install dependencies on node_modules directory.
npm install
or you can update the dependencies to use latest version (will override currently installed dependencies on node_modules directory) using npm update
npm update
You don't have to put the dependency you want manually to package.json, you just use command npm install {package-name} with additional option like --save / --save-dev / --save-optional.
In example you want to add dependency of node-q to your application, you can do this:
npm install q --save
Juggling into different option --save-prefixed value will act as follows,
--save will add dependency to dependencies attribute of your package.json, it will be installed mainly for your application
--save-dev will add dependency to devDependencies attribute of your package.json, it will be installed for development phase of your application (usually it is testing dependencies)
--save-optional will installed for optional (nice to have) dependencies. I rarely used it for my applications or libraries anyway.
Don't forget you MUST run commands from your application directory (the one that node_modules directory resides).