npm - 我编辑了我的 npm init 配置,现在我无法将其重置为默认值
问题描述
我试图设置一个默认名称,所以我不必每次都输入它,但无论我做什么最终都会弄乱我的 package.json 文件的创建。现在,当我在一个新项目中键入“npm init”时,它不会询问通常的提示并设置文件,它只包含“名称”和“版本”。控制台日志如下:
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help init` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
About to write to /Users/chris/Documents/App Brewery/todo-v1/package.json:
{
"name": "",
"version": ""
}
Is this OK? (yes)
我试图编辑我的配置文件,但是当我这样做时,我收到了这个错误:
npm ERR! code ENOENT
npm ERR! syscall spawn subl
npm ERR! path subl
npm ERR! errno ENOENT
npm ERR! enoent spawn subl ENOENT
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/chris/.npm/_logs/2020-06-29T21_18_00_116Z-debug.log
日志文件是:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/Cellar/node/10.1.0/bin/node',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli 'config',
1 verbose cli 'edit' ]
2 info using npm@6.14.5
3 info using node@v10.1.0
4 verbose stack Error: spawn subl ENOENT
4 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:227:19)
4 verbose stack at onErrorNT (internal/child_process.js:404:16)
4 verbose stack at process._tickCallback (internal/process/next_tick.js:63:19)
5 verbose cwd /Users/chris/Documents/App Brewery/todo-v1
6 verbose Darwin 19.5.0
7 verbose argv "/usr/local/Cellar/node/10.1.0/bin/node" "/usr/local/bin/npm" "config" "edit"
8 verbose node v10.1.0
9 verbose npm v6.14.5
10 error code ENOENT
11 error syscall spawn subl
12 error path subl
13 error errno ENOENT
14 error enoent spawn subl ENOENT
15 error enoent This is related to npm not being able to find a file.
16 verbose exit [ 1, true ]
我对终端等知之甚少,无法理解错误或如何修复它们。有人可以给我一些建议吗?如果有帮助,我正在使用 zsh...
谢谢!
解决方案
如果有人有更好的答案或可以澄清事情,我会全力以赴。
通过创建文件 .npm-init.js 并使用 module.exports 将所有默认值添加回来,我能够让某些东西再次工作。我不确定这是否会长期有效,或者是否是正确的做事方式,但至少我又有一个 package.json 文件?
var cwd = process.cwd(),
name = cwd.split("/").pop();
module.exports = {
name: name,
description: "",
version: "1.0.0",
main: "app.js",
scripts: {
start: "node app.js",
dev: "nodemon app.js"
},
keywords: [],
author: "",
license: ""
};
推荐阅读
- microsoft-graph-api - 如何在 Microsoft Teams 中将 PDF-Viewer 选项卡添加到频道?
- python - 在命名中读取具有特定字符的多个 csv 文件
- php - 引用资源中的资源时 Laravel 错误
- xml - 如何在菜单中添加选项,Eclipse 插件
- git - 从回购中提取的 VSTS 步骤
- python - Python Web Scraping - 出现错误时的电子邮件通知
- wordpress - 从 Divi 主题更改标题模板
- firebase - 如何在后端使用 Firebase 云功能通过直接函数调用应用身份验证中间件
- sql - 后端 api 是否应该存储布局信息?
- vb.net - 如何计算借方和贷方列以在 ListView 的第三列中显示每一行?