mikaelbr / gulp-notify

gulp plugin to send messages based on Vinyl Files or Errors to Mac OS X, Linux or Windows using the node-notifier module. Fallbacks to Growl or simply logging
MIT License
592 stars 40 forks source link

Error: SyntaxError in plugin 'gulp-notify' #129

Open dmhendricks opened 5 years ago

dmhendricks commented 5 years ago
Component Version Installed
gulp-notify v3.2.0
Operating System Mac OS X 10.14.3 Mojave
Gulp v4.0.0
Node.js v10.14.2
npm v6.8.0

I have gotten the error, "SyntaxError in plugin 'gulp-notify'" with various projects with which I use gulp-notify. I have Gulp logging errors to the console:

.on( 'error', console.error.bind( console ) )

I'd like to keep logging errors to the console, but I'd rather not get these errors. Full text of the error:

Message:
    Unexpected token { in JSON at position 129
[12:00:00] gulp-notify: [Error in notifier] SyntaxError in plugin "gulp-notify"

Thank you for the plugin! Daniel

petr0n commented 5 years ago

Have the same issue.

[Error in notifier] SyntaxError in plugin "gulp-notify"

jonsaul commented 5 years ago

Same:

[15:56:02] gulp-notify: [Error in notifier] SyntaxError in plugin "gulp-notify" Message: Unexpected token { in JSON at position 133

luniablue commented 5 years ago

Same issue here as well:

[15:48:55] gulp-notify: [Error in notifier] SyntaxError in plugin "gulp-notify" Message: Unexpected token { in JSON at position 129

orsem commented 5 years ago

Same here:

[21:03:20] gulp-notify: [Error in notifier] SyntaxError in plugin "gulp-notify" Message: Unexpected token { in JSON at position 129

raymondSmith501 commented 5 years ago

Same here. Any thoughts?

max-sixblade commented 5 years ago

Same here, any thoughts when it might be fixed? Thanks.

mahammedzkhan commented 5 years ago

Use double quotes and pass your object as JSON(quotes around your properties):

notify({
  "title": "Gulp Task Complete",
  "message": "Message"
 })
yumitsu commented 5 years ago

@mahammedzkhan Thanks for your hint, it helped.

mgaw commented 5 years ago

Hi!

I also ran into this error and tried to debug it a little bit. I was able to reproduce it using this script:

cp = require('child_process');

cmd = '/usr/local/lib/node_modules/node-notifier/vendor/mac.noindex/terminal-notifier.app/Contents/MacOS/terminal-notifier';
options = [
    '-title', '"Hello from mgaw"',
    '-message', '"Trying to trigger invalid JSON"',
    '-hint', '"int:transient:1"',
    '-timeout', '"1"',
    '-json', '"true"'
];

x = () => {
    process = cp.execFile(cmd, options, (err, stdout, stderr) => {
        console.log('--- Response on stdout that should be valid JSON:\n' + stdout + '\n---\n');
    });
    console.log('Triggered notification, waiting for it to time out...');
}

range = n => [...Array(n).keys()];

range(10).forEach(x);

When I run it, often I will see this response, which I guess is the expected valid JSON:

{
  "activationType" : "timeout",
  "activationAt" : "2019-07-12 14:44:33 +0200",
  "deliveredAt" : "2019-07-12 14:44:32 +0200"
}

However sometimes two (or more) of those responses are concatenated together in a response such as:

{
  "activationType" : "timeout",
  "activationAt" : "2019-07-12 14:44:33 +0200",
  "deliveredAt" : "2019-07-12 14:44:31 +0200"
}{
  "activationType" : "timeout",
  "activationAt" : "2019-07-12 14:44:33 +0200",
  "deliveredAt" : "2019-07-12 14:44:31 +0200"
}

The SyntaxError happens when gulp-notify tries to parse this response.

This was using version 1.7.2 of terminal-notifier:

$ /usr/local/lib/node_modules/node-notifier/vendor/mac.noindex/terminal-notifier.app/Contents/MacOS/terminal-notifier
terminal-notifier (1.7.2) is a command-line tool to send OS X User Notifications.
tristanhall commented 5 years ago

@mgaw I was seeing the same behavior while trying to debug this on my machine as well. terminal-notifier v1.7.2 npm v6.10.1 node v12.4.0 macOS v10.14.5

MCStreetguy commented 5 years ago

I had the same problem just now but the solution @mahammedzkhan mentioned works fine.

yumitsu commented 5 years ago

@mahammedzkhan Dunno why - after your solution there were few notifications, and then gulp-notify broken completely. I guess this issue somehow related to vendored terminal-notifier, as OSX version works just OK.

kirstylmarks commented 1 year ago

Hi,

Has there been any resolve on this at all? I am coming up against this issue.

Using Gulp Notify 4.0.0 Node : 20.6.1

Thanks in advance

kirstylmarks commented 1 year ago

Use double quotes and pass your object as JSON(quotes around your properties):

notify({
  "title": "Gulp Task Complete",
  "message": "Message"
 })

Hi,

Have you tested this in even later versions of node? Definitely seems as if this plugin is not going to be supported anymore as later versions total fail with the notification system.