sindresorhus/alfy

Cannot read property 'alfy' of undefined

IAIAE opened this issue · 3 comments

IAIAE commented

the index.js is

const alfy = require('alfy');
alfy.output([{
title: 'Unicorn'
}, {
title: 'Rainbow'
}]);

and the console outputs the error:

[ERROR: input.scriptfilter] Code 1: {
  "items": [
    {
      "title": "Unicorn"
    },
    {
      "title": "Rainbow"
    }
  ]
}
{
  "items": [
    {
      "title": "TypeError: Cannot read property 'alfy' of undefined\n    at readPkgUp.then.result (/Users/pro/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.0408C61C-45B8-474D-B77D-B3C6691E4024/node_modules/alfy/lib/update-notification.js:7:26)",
      "subtitle": "Press ⌘L to see the full error and ⌘C to copy it.",
      "valid": false,
      "text": {
        "copy": "```\nTypeError: Cannot read property 'alfy' of undefined\n    at readPkgUp.then.result (/Users/pro/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.0408C61C-45B8-474D-B77D-B3C6691E4024/node_modules/alfy/lib/update-notification.js:7:26)\n```\n\n-\nregurl undefined\nAlfred 3.3.2\ndarwin x64 15.6.0",
        "largetype": "TypeError: Cannot read property 'alfy' of undefined\n    at readPkgUp.then.result (/Users/pro/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.0408C61C-45B8-474D-B77D-B3C6691E4024/node_modules/alfy/lib/update-notification.js:7:26)"
      },
      "icon": {
        "path": "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns"
      }
    }
  ]
}
[2017-06-03 16:11:59][ERROR: input.scriptfilter] JSON error: Garbage at end. in JSON:
{
  "items": [
    {
      "title": "Unicorn"
    },
    {
      "title": "Rainbow"
    }
  ]
}
{
  "items": [
    {
      "title": "TypeError: Cannot read property 'alfy' of undefined\n    at readPkgUp.then.result (/Users/pro/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.0408C61C-45B8-474D-B77D-B3C6691E4024/node_modules/alfy/lib/update-notification.js:7:26)",
      "subtitle": "Press ⌘L to see the full error and ⌘C to copy it.",
      "valid": false,
      "text": {
        "copy": "```\nTypeError: Cannot read property 'alfy' of undefined\n    at readPkgUp.then.result (/Users/pro/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.0408C61C-45B8-474D-B77D-B3C6691E4024/node_modules/alfy/lib/update-notification.js:7:26)\n```\n\n-\nregurl undefined\nAlfred 3.3.2\ndarwin x64 15.6.0",
        "largetype": "TypeError: Cannot read property 'alfy' of undefined\n    at readPkgUp.then.result (/Users/pro/Library/Application Support/Alfred 3/Alfred.alfredpreferences/workflows/user.workflow.0408C61C-45B8-474D-B77D-B3C6691E4024/node_modules/alfy/lib/update-notification.js:7:26)"
      },
      "icon": {
        "path": "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns"
      }
    }
  ]
}

Do you have a package.json file in your project directory? It looks like it can't find it.

I just got that error when going through the steps for example workflow in the readme.rd file. Based on Sam's comment I ran 'npm init' and it works now.

Exactly, you need a package.json file. I will have a look if I can make the error message more clear.