Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a package.json file?

Warning: Total noob wading in unchartered waters. Here goes. 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.

like image 860
Stickup Artist Avatar asked Jan 06 '23 07:01

Stickup Artist


2 Answers

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
like image 160
nem035 Avatar answered Jan 13 '23 08:01

nem035


Use: npm init -y

Then install your packages.

That worked for me when I had the same problem.

like image 25
meshalsuccess Avatar answered Jan 13 '23 08:01

meshalsuccess