Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 带有electron updater和Sinopia的节点注册表路径_Node.js_Npm_Electron_Sinopia - Fatal编程技术网

Node.js 带有electron updater和Sinopia的节点注册表路径

Node.js 带有electron updater和Sinopia的节点注册表路径,node.js,npm,electron,sinopia,Node.js,Npm,Electron,Sinopia,我目前正在开发一个运行在Electron(以前的atom shell)上的应用程序,并试图设计一种在新的更新可用时提醒用户的方法。为此,我将按照中描述的方式使用。我还配置为监听http://localhost:4873/(默认行为)并运行此命令行: npm配置集注册表”http://localhost:4873“ 我检查了.npmrc文件,注册表已正确设置了新值。 我遇到的问题是,当我尝试检查更新时,我在控制台中收到以下错误消息: {[HTTPError:响应代码404(未找到)] 消息:“响应

我目前正在开发一个运行在Electron(以前的atom shell)上的应用程序,并试图设计一种在新的更新可用时提醒用户的方法。为此,我将按照中描述的方式使用。我还配置为监听
http://localhost:4873/
(默认行为)并运行此命令行:
npm配置集注册表”http://localhost:4873“
我检查了
.npmrc
文件,注册表已正确设置了新值。
我遇到的问题是,当我尝试检查更新时,我在控制台中收到以下错误消息:

{[HTTPError:响应代码404(未找到)]
消息:“响应代码404(未找到)”,
代码:未定义,
主机:“registry.npmjs.org”,
主机名:“registry.npmjs.org”,
方法:'GET',
路径:'/hacker keyboard electron',
状态代码:404,
statusMessage:“未找到”}

因此,我相信我在npm的配置中忘记了一些东西,它使应用程序侦听npm的常规路径,而不是Sinopia服务器。问题是什么?
请在下面找到我正在使用的代码:

foobar生成器
├── 应用程序
├── 鲍尔组件
├── bower.json
├── index.html
├── 指数js
├── 梅因。js
├── nbproject
├── 节点模块
├── npm debug.log
├── package.json
├── 自述。md
└── 中国

package.json

{
    "name": "foobar-generator",
    "version": "0.0.1",
    "description": "A generator for foobar",
    "main": "main.js",
    "dependencies": {
        "angular": "^1.4.7",
        "bootstrap": "^3.3.5",
        "chokidar": "^1.2.0",
        "electron-debug": "^0.2.1",
        "electron-packager": "^5.1.0",
        "electron-plugins": "^0.0.4",
        "electron-prebuilt": "^0.33.6",
        "electron-rebuild": "^1.0.2",
        "electron-updater": "^0.2.0",
        "grunt": "^0.4.5",
        "jquery": "^2.1.4"
    },
    "devDependencies": {},
    "publishConfig": {
        "registry": "http://localhost:4873/"
    },
    "registry": "http://localhost:4873/"
}
main.js

var appli = require('app');
var BrowserWindow = require('browser-window');
var updater = require('electron-updater');
var util = require('util');

// Report crashes to our server.
require('crash-reporter').start();

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
var mainWindow = null;
var loaded = false;

// Quit when all windows are closed.
appli.on('window-all-closed', function () {
    // On OS X it is common for applications and their menu bar
    // to stay active until the user quits explicitly with Cmd + Q
    if (process.platform !== 'darwin') {
        appli.quit();
    }    
});

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
appli.on('ready', function () {
    updater.on('ready', function () {
        // Create the browser window.
        mainWindow = new BrowserWindow({width: 800, height: 600});

        // and load the index.html of the app.
        mainWindow.loadUrl('file://' + __dirname + '/index.html');

        mainWindow.openDevTools({detach: true});

        mainWindow.on('closed', function () {
            mainWindow = null;
        });
    });
    updater.on('updateRequired', function () {
        appli.quit();
    });
    updater.on('updateAvailable', function () {
        if (mainWindow) {
            mainWindow.webContents.send('update-available');
        }
    });
    updater.start();
    updater.check(function (err, results) {
        if (err) {
            return console.error(util.inspect(err));
        }
        console.log(results);
    });
});

你们看到我可能忘记/做错了什么吗?

通过阅读npmrc的手册(
npm帮助npmrc
),我发现
.npmrc
文件不是唯一的。通过像我那样配置注册表,我只更改了每个用户
.npmrc
。但是在您的项目根目录中也应该有这样一个文件!您应该在其中配置要使用的注册表。在项目根目录中添加此文件解决了我面临的问题。

您应该侦听错误事件。 试试这个

updater.on('error', function (err) {
    console.log(err);
});