如何创建 package.json 文件? [英] How do I create a package.json file?
问题描述
警告:新手在未知水域涉水.开始.在 Mac 终端中:
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.
指的是什么实用程序?
接下来:
Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.
Name: (portfolio)
我输入:
npm install <portfolio> --save
终端打印出来:
Sorry, name can only contain URL-friendly characters.
我的命名有什么问题?我正在使用 Meteor、Mac OSX 在我的本地机器上工作
What am I doing wrong with my naming? I'm working on my local machine with Meteor, Mac OSX
谢谢!
推荐答案
要创建 package.json
,您可以运行 npm init(并查看其选项)或基于 这些规则.
To create package.json
, you can run npm init (and go through its options) or manually create the file based on these rules.
这是一个简单的package.json
:
{
"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",
}
}
现在,就错误而言:
抱歉,名称只能包含对 URL 友好的字符.
Sorry, name can only contain URL-friendly characters.
这意味着包名称不符合 命名之一规则,主要是:
It means that the package name doesn't meet one of the naming rules, mainly:
包名不得包含任何非 url 安全字符(因为名称最终成为 URL 的一部分)
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 <>
.
What <>
means 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.
这是定义 npm install
命令的方式,而不是使用它:
It is how you would define an npm install
command, not use it:
定义:
npm install <package_name_goes_here>
用法
npm install portfolio
这篇关于如何创建 package.json 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!