hubot-slack throwing an error on startup - node.js

I am trying to add a new hubot integration to our Slack channels. I am setting this up on a Windows machine and am deploying to a Heroku server. I followed the installation instructions provided here: https://github.com/slackhq/hubot-slack
I can create and run a new hubot instance on my local computer (calling "bin/hubot" in a Powershell prompt), but when I install the hubot-slack package and add "hubot-slack" to the external-scripts file I get an error. If I remove the value from the external-scripts file everything is fine.
PS C:\hubot> bin/hubot
jarvis> [Tue Dec 22 2015 15:18:24 GMT-0800 (Pacific Standard Time)] ERROR Error loading scripts from npm package - TypeError: require(...) is not a function
at Robot.loadExternalScripts (C:\hubot\node_modules\hubot\src\robot.coffee:399:11)
at C:\hubot\node_modules\hubot\bin\hubot:128:26
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
If I include the adapter flag for Slack I get a different error. I tried setting HUBOT_SLACK_TOKEN as a System Environment variable.
PS C:\hubot> bin/hubot -a slack
[Tue Dec 22 2015 15:21:54 GMT-0800 (Pacific Standard Time)] ERROR No services token provided to Hubot
Every example I can find is including the HUBOT_SLACK_TOKEN in the call to hubot, but it doesn't work for me (I must be missing something).
PS C:\hubot> HUBOT_SLACK_TOKEN=xoxb-22211110000-123456781234ZZZZYYYYXXXX ./bin/hubot --adapter slack
HUBOT_SLACK_TOKEN=xoxb-17240119159-dBeAEc2X8M2O9vJBYzWj5KFW : The term
'HUBOT_SLACK_TOKEN=xoxb-17240119159-dBeAEc2X8M2O9vJBYzWj5KFW' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
At line:1 char:1
+ HUBOT_SLACK_TOKEN=xoxb-22211110000-123456781234ZZZZYYYYXXXX ./bin/hubot --adapte ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (HUBOT_SLACK_TOK...234ZZZZYYYYXXXX:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
To rule out something locally I deployed the application to Heroku, but I got a different error.
2015-12-22T22:28:49.426496+00:00 heroku[web.1]: State changed from crashed to starting
2015-12-22T22:14:54.739959+00:00 heroku[web.1]: State changed from starting to up
2015-12-22T22:14:55.133113+00:00 app[web.1]: [Tue Dec 22 2015 22:14:55 GMT+0000 (UTC)] ERROR Error loading scripts from npm package - TypeError: object is not a function
2015-12-22T22:14:55.133117+00:00 app[web.1]: at Robot.loadExternalScripts (/app/node_modules/hubot/src/robot.coffee:399:11, <js>:269:39)
2015-12-22T22:14:55.133119+00:00 app[web.1]: at fs.js:272:14
2015-12-22T22:14:55.133121+00:00 app[web.1]: at Object.oncomplete (fs.js:108:15)
2015-12-22T22:14:56.115333+00:00 heroku[web.1]: State changed from up to crashed
package.json:
{
"name": "jarvis",
"version": "0.0.0",
"private": true,
"author": "Me <email#domain.com>",
"description": "A friendly robot",
"dependencies": {
"hubot": "^2.17.0",
"hubot-diagnostics": "0.0.1",
"hubot-google-images": "^0.2.6",
"hubot-google-translate": "^0.2.0",
"hubot-help": "^0.1.2",
"hubot-heroku-keepalive": "^1.0.1",
"hubot-maps": "0.0.2",
"hubot-pugme": "^0.1.0",
"hubot-redis-brain": "0.0.3",
"hubot-rules": "^0.1.1",
"hubot-scripts": "^2.16.2",
"hubot-shipit": "^0.2.0",
"requirejs": "^2.1.22",
"hubot-slack": "^3.4.2"
},
"engines": {
"node": "0.10.x"
}
}
external-scripts.json
[
"hubot-diagnostics",
"hubot-help",
"hubot-heroku-keepalive",
"hubot-google-images",
"hubot-google-translate",
"hubot-pugme",
"hubot-maps",
"hubot-redis-brain",
"hubot-rules",
"hubot-shipit",
"requirejs",
"hubot-slack"
]

On Windows, it seems that the mechanism is a little different from what it processes in Linux. The error 'HUBOT_SLACK_TOKEN is not recognized' is raised because it would read the value of 'HUBOT_SLACK_TOKEN' from environment variables in windows.
Create an environment variable 'HUBOT_SLACK_TOKEN' manually and set the value, it will work.
You could check it out in the source code in the github repo: slack.coffee.
options =
token: process.env.HUBOT_SLACK_TOKEN
autoReconnect: !exitProcessOnDisconnect
autoMark: true
exitOnDisconnect: exitProcessOnDisconnect
proxyUrl: process.env.https_proxy

What intrigues me is this particular line:
Error loading scripts from npm package - TypeError: require(...) is not a function
Did you add the other scripts from the repo aswell?
There also might be something wrong with the node/npm/coffee installation/version on your windows machine. Make sure that those are installed and in a compatible version. Another thread had an issue with incompatible versions. Please tell us about the versions you use and try downgrading node to 0.12.x.
The way you use the token is fine.

Related

Electron and couchbase: the module was compiled against a different node.js version (win)

Question:
I am trying to use couchbase in an electron application, but fail to run the electron application as soon as I include the couchbase module. How can I use couchbase with electron?
Error message:
C:\dev\app>npm start
> eej#1.0.0 start C:\dev\app
> electron .
App threw an error during load
Error: The module '\\?\C:\dev\app\node_modules\couchbase\build\Release\couchbase_impl.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 76. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
at process.func (electron/js2c/asar.js:140:31)
at process.func [as dlopen] (electron/js2c/asar.js:140:31)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1016:18)
at Object.func (electron/js2c/asar.js:140:31)
at Object.func [as .node] (electron/js2c/asar.js:140:31)
at Module.load (internal/modules/cjs/loader.js:816:32)
at Module._load (internal/modules/cjs/loader.js:728:14)
at Module._load (electron/js2c/asar.js:717:26)
at Function.Module._load (electron/js2c/asar.js:717:26)
at Module.require (internal/modules/cjs/loader.js:853:19)
My main.js file begins like this:
const { app, BrowserWindow } = require('electron')
var couchbase = require('couchbase');
function createWindow () {
What I have tried already:
removing the node_modules directory and lock file and reinstalling via npm i
installing and running electron-rebuild
using the --update-binary switch when running npm i
downgraded the npm version to an LTS version
Background information:
Node version:
PS C:\dev\app> node --version
v12.16.1
PS C:\dev\app> electron --version
v8.0.1
Electron uses node 12.13.0:
We are using node 12.13.0, Chrome 80.0.3987.86, and Electron 8.0.1.
The version of electron-node and standalone node differ. I am not sure if this is okay?!
Content of my package.json file:
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"author": "",
"license": "ISC",
"devDependencies": {
"couchbase": "^3.0.0",
"electron": "^8.0.1",
"electron-rebuild": "^1.10.0"
},
"dependencies": {
"node-gyp": "^6.1.0"
}
}
Similar questions:
Couchbase Node compiled against different node version: After I have added a comment I discovered that it is a unix specific question.
Node - was compiled against a different Node.js version using NODE_MODULE_VERSION 51: I went through nearly all of the suggestions, but none of them seemed to work for me.

Node app on heroku fails due to read only filesystem

I have a very simple TypeScript app (build with Express.js) that runs on Node which I deploy to Heroku. I use both the node buildpack and zidizei/heroku-buildpack-tsc, the latter of which compiles the .ts to JavaScript at deploy time.
This has worked fine up to today when I tried to run a deploy. The deployment itself works fine but the app crashes subsequently at the point at which the launch script node ./dist/server.js is run. Logs here:
Sep 06 14:43:33 goodlord-bark app/web.1: $ node ./dist/server.js
Sep 06 14:43:33 goodlord-bark heroku/web.1: Process exited with status 1
Sep 06 14:43:33 goodlord-bark heroku/web.1: State changed from starting to crashed
Sep 06 14:43:33 goodlord-bark app/web.1: error An unexpected error occurred: "EROFS: read-only file system, access '/usr/local/bin'".
Sep 06 14:43:33 goodlord-bark app/web.1: info If you think this is a bug, please open a bug report with the information provided in "/app/yarn-error.log".
At no point does any script or my app attempt to write to /usr/local/bin so I'm confused as to why this is happening. This error only occurred following a superficial change to the codebase and new deploy so it strikes me something has changed on Heroku's end but I can get to the bottom of it.
Rolling back to a previous deploy has kept my app running for the time being, but I'm currently unable to deploy any updates.
There is also no /app/yarn-error.log to examine.
I just had similar issue on Heroku all of a sudden. Turns out the issue was introduced at yarn 1.0.0 and Heroku use the latest version by default. Here's a relevant heroku-buildpack-nodejs issue.
Fixed by downgrading yarn in engines section of package.json:
"engines": {
"node": "^7.10.1",
"yarn": "0.27.5"
}

Issue deploying to elastic beanstalk "50npm.sh failed"

I'm having an issue deploying some code to one of my environments.
Creating application version archive "app-aa68e-170213_103330".
Uploading PAS-API/app-aa68e-170213_103330.zip to S3. This may take a while.
Upload Complete.
INFO: Environment update is starting.
INFO: Deploying new version to instance(s).
ERROR: Failed to run npm install. Snapshot logs for more details.
ERROR: [Instance: i-0ee97a5c7bcab8d51] Command failed on instance. Return code: 1 Output: (TRUNCATED)..."/opt/elasticbeanstalk/containerfiles/ebnode.py", line 180, in npm_install
raise e
subprocess.CalledProcessError: Command '['/opt/elasticbeanstalk/node-install/node-v4.4.6-linux-x64/bin/npm', '--production', 'install']' returned non-zero exit status 1.
Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
INFO: Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
ERROR: Unsuccessful command execution on instance id(s) 'i-0ee97a5c7bcab8d51'. Aborting the operation.
It seems that the deployment is failing when npm install is running on the server.
When I checked the package.json it seemed some of the deps were added as a tarball instead of a version number, meaning that when it installed and saved it looked like this:
"basic-auth": "https://registry.npmjs.org/basic-auth/-/basic-auth-1.0.4.tgz"
Rather than
"basic-auth": "^1.1.0",
This was failing on npm install on the eb instance, it looks like it works now.
If it was OK before and you didn't change deployment settings, you can reboot the instance and it usually solve the problem.

Grunt error when running Sails.js app in Amazon ElasticBeanstalk

I am moving a Sails.js app hosted on Heroku to Amazon ElasticBeanstalk. When the application launches, it throws the following Grunt error (pulled from eb logs):
info: Sails <| .-..-.
info: v0.11.5 |\
info: /|.\
info: / || \
info: ,' |' \
info: .-'.-==|/_--'
info: `--'-------'
info: __---___--___---___--___---___--___
info: ____---___--___---___--___---___--___-__
info:
info: Server lifted in `/var/app/current`
info: To see your app, visit http://localhost:8081
info: To shut down Sails, press <CTRL> + C at any time.
debug: --------------------------------------------------------
debug: :: Mon Feb 29 2016 08:21:46 GMT+0000 (UTC)
debug: Environment : development
debug: Port : 8081
debug: --------------------------------------------------------
error: ** Grunt :: An error occurred. **
error:
------------------------------------------------------------------------
>> FileError: '../bower_components/bootstrap/less/grid.less' wasn't found in assets/styles/importer.less on line 9, column 1:
>> 8 // Import Bootstrap
>> 9 #import "../bower_components/bootstrap/less/grid.less";
>> 10 #import "../bower_components/bootstrap/less/mixins.less";
Warning: Error compiling assets/styles/importer.less
Aborted due to warnings.
Running "less:dev" (less) task
------------------------------------------------------------------------
error: Looks like a Grunt error occurred--
error: Please fix it, then **restart Sails** to continue running tasks (e.g. watching for changes in assets)
error: Or if you're stuck, check out the troubleshooting tips below.
error: Troubleshooting tips:
error:
error: *-> Are "grunt" and related grunt task modules installed locally? Run `npm install` if you're not sure.
error:
error: *-> You might have a malformed LESS, SASS, CoffeeScript file, etc.
error:
error: *-> Or maybe you don't have permissions to access the `.tmp` directory?
error: e.g., `/var/app/current/.tmp` ?
error:
error: If you think this might be the case, try running:
error: sudo chown -R 497 /var/app/current/.tmp
The same code runs fine on my local development laptop and on Heroku but not on ElasticBeanstalk. Why is it unable to find the bootstrap files? This being a PaaS, I can't even run the recommended sudo chown command that the log recommended. Also to be clear, I have the following command in my package.json file:
"scripts": {
"postinstall": "bower install; grunt build",
"debug": "node debug app.js",
"start": "node app.js"
}
I have instructed the script to run bower install after the NPM packages are installed in the machine. None of the images in my /assets folder seem to load either. Not sure what's going on. Please help.

What is the issue "node" is working but "nodemon" is not woking on windows 7 64-bit in node.js?

I am new to node.js. node is working fine but when I installed the nodemon package, it gives an error: exception in nodemon killing node, even when installed globally.
22 Jun 13:07:29 - [nodemon] v1.3.7
22 Jun 13:07:29 - [nodemon] to restart at any time, enter `rs`
22 Jun 13:07:29 - [nodemon] watching: *.*
22 Jun 13:07:29 - [nodemon] starting `node server.js`
exception in nodemon killing node
Error: spawn cmd ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1053:32)
at child_process.js:1144:20
at process._tickCallback (node.js:355:11)
----------------------------------------------------------
If appropriate, please file an error with the output from:
$ node
C:\Users\username\AppData\Roaming\npm\node_modules\nodemon\bin\nodemon.
js server.js --dump
At http://github.com/remy/nodemon/issues/new
Possible solutions.
1. Permissions
The problem may be in your file permissions. Execute in git bash or from windows to give full permission to the project folder.
$ chmod -R 777 [folder]
2. Environment Variables
Missing "C:\Windows\System32" in the PATH.
Github issue
3. Reinstall
Altogether remove nodemon using npm and try reinstalling.
npm uninstall -g nodemon
4. Update nodejs
If you have an old version of NodeJS, try updating it. I prefer entirely removing NodeJS and reinstalling it again.
Step by steps to remove NodeJS in windows
Note: Your question may not be rich enough to answer correctly. Please include more information about questions if those didn't work.
Help spawn to locate your nodemon.cmd like this:
var nodemonCmd = (process.platform == 'win32') ? 'node_modules\\.bin\\nodemon.cmd' : 'nodemon'
myApp = spawn(nodemonCmd, ['build/server.bundle']);
Hope it works :)

Resources