Nodemailer: require is not defined - node.js

I have a problem using Nodemailer. These are the instructions I follow: http://www.nodemailer.com/docs/install
I'm using Grunt server.
Step 1
I start writing this command inside my project folder:
npm install nodemailer --save
And everything seems to be working, the nodemailer folder appears inside node_modules folder and inside package.json I have this line of code:
"dependencies": {
"nodemailer": "^0.6.3"
},
Step 2
I try to reference to the nodemailer by writing this inside my javascript file:
var nodemailer = require("nodemailer");
Error
But then I get this error: Uncaught ReferenceError: require is not defined
Other methods
I have also tryed to do the following:
require("nodemailer.js");
require("/..path.../nodemailer.js");
But nothing seems to work.
Have anyone any idea why I can't access nodemailer? Please keep in mind that I'm new to javascript. Thank you :)

Related

How to integrate Dialogflow API v2 with MS BotFramework using dialogflow-nodejs-client-v2

I am building a bot using MS BotFramework functions and I am trying to use Dialogflow with MS BotFramework but I am failing with setting up configuration. dialogflow-nodejs-client-v2 library requires that GOOGLE_APPLICATION_CREDENTIALS environment variable is set. Which I believe I set :
I've also manually uploaded conf file into the, what I believe is the working directory
Yet bot is still failing. I tried various paths as value of a variable including absolute path : D:\home\site\wwwroot\messages\test-0691d01dae88.json
still with no luck.
Error I am getting is very cryptic :
Exception while executing function: Functions.messages. mscorlib: One or more errors occurred. Error: package.json does not exist at D:\home\site\wwwroot\package.json
at Object.module.exports.exports.find (D:\home\site\wwwroot\.funcpack\index.js:272715:15)
at Object.module.exports.exports.status.OK (D:\home\site\wwwroot\.funcpack\index.js:51739:12)
at __webpack_require__ (D:\home\site\wwwroot\.funcpack\index.js:21:30)
at Object.<anonymous> (D:\home\site\wwwroot\.funcpack\index.js:271412:12)
at __webpack_require__ (D:\home\site\wwwroot\.funcpack\index.js:21:30)
at Object.module.exports.module.exports (D:\home\site\wwwroot\.funcpack\index.js:84837:27)
at __webpack_require__ (D:\home\site\wwwroot\.funcpack\index.js:21:30)
at Object.<anonymous> (D:\home\site\wwwroot\.funcpack\index.js:260961:14)
at __webpack_require__ (D:\home\site\wwwroot\.funcpack\index.js:21:30)
at new GrpcClient (D:\home\site\wwwroot\.funcpack\index.js:132359:25).
It suggest package.json is missing but this error only occurs if I try to use dialog flow to be specific I require recognizer.js file in index.js.
var apiairecognizer_v2 = require('./recognizer');
It's content is :
"use strict";
const dialogflow = require('dialogflow').v2beta1;
const uuid = require('uuid');
// next line causes error
const sessionClient = new dialogflow.SessionsClient();
var ApiAiRecognizer = function(){
};
ApiAiRecognizer.prototype.recognize = function (context, done){
}
module.exports = ApiAiRecognizer;
Commenting out sessionClient line will make bot work.
Any idea how to configure Dialogflow v2 with MS BotFramework functions?
thanks
Error seems straight forward for any node.js application. You are using statement:
var apiairecognizer_v2 = require('./recognizer');
So application is expecting package.json file for installing packages like:
{
"name": "abc",
"devDependencies": {
"dialogflow":"^0.6.0",
"uuid":"^3.3.2",
"recognizer":"^0.0.2"
}
}
it is used for installing package by npm.
Error is that it is expecting package.json with all referenced & dependent packages there in location D:\home\site\wwwroot\package.json
You can either manually add that or try going to that folder if node is installed & npm is used, try
npm install --save recognizer
or
npm install --save-dev recognizer
it will save latest package in package.json.
It seems you are already getting two packages dialogflow & uuid resolved using npm without error so issue is missing recognizer entry in package.json.
Try adding package in package.json there.

Module not found : 'child process'

I'm developing a ReactJS app with Babel and Webpack. I am using the create-react-app facebook script so it handles the Webpack´s configuration. My problem is that I created a js file and add:
var childProcess = require('child_process');
But when I want to compile the new version i get the following error :
Module not found: 'child_process'.
I don't know what to do with this . I have read that adding custom configurations to the webpack.config.js may be the solution but i am using create react app so I don't have the Webpack configuration. I tried running npm run eject and create my own webpack.config.js but it doesn't work.
I hope somebody could help me.
You need to configure the correct target inside the webpack configuration: https://webpack.github.io/docs/configuration.html#target
module.exports = {
entry: './path/to/my/entry/file.js',
...
target: 'node',// we can use node.js modules after adding this configuration
};

How to update express/lib/application.js to match different app.js file?

MEAN noob here. I was following this tutorial, but npm start gives me the following error:
Error: Cannot find module './view'...
at Object.<anonymous> (C:\root\node_modules\express\lib\application.js:22:12)
This is what application.js says at that location:
var query = require('./middleware/query');
var debug = require('debug')('express:application');
var View = require('./view'); /////// line 22
I have a lib/middleware but not a lib/view, nor lib/util...
My theory is perhaps I screwed the express installation up: It's possible I didn't have the correct app.js in place when I installed it. Does app.js affect express's installation?
Is there a way to rebuild express or express/lib without uninstalling & reinstalling everything?
Would this even fix my problem?

Angular2 + Webpack DefinePlugin not working?

I tried to run the Angular2 app from the tutorial on the angular.io website
Angular2 with Webpack Tutorial on angular.io
Installation worked well (with a few hiccups, it's Ubuntu 14.04 LTS) but I got to the point where the npm start task works, the server works, and even the app works in the browser, so far so good. But
Everytime I run npm start, I get the following 2 errors in the terminal, AND in the browser console:
ERROR in ./src/polyfills.ts
(4,5): error TS2304: Cannot find name 'process'.
ERROR in ./src/main.ts
(7,5): error TS2304: Cannot find name 'process'.
If you look at the tutorial, it is explained how to create the webpack configs, there is a webpack.common.js, a webpack.prod.js and a webpack.dev.js. In the webpack.prod.js, a var is created with this code:
const ENV = process.env.NODE_ENV = process.env.ENV = 'production';
new webpack.DefinePlugin({
'process.env': {
'ENV': JSON.stringify(ENV)
}
})
In main.ts and in polyfills.ts the var is referenced by this:
if (process.env.ENV === 'production') {
enableProdMode();
}
but it seems, that Typings does not know how to inject these variables, created with webpack.DefinePlugin into the compiled Javascript (that's what I'm thinking, I maybe wrong)
If anyone ran into the same problem, or anyone can help me with this, I would be very thankful! (All the code is from the tutorial, so anyone who tried the tutorial may have run into the same problem, I guess?!)
Thank You!
I was having the same issue here (doing the same tutorial). To solve this I created a file named typings.d.ts on the same folder where typings.json is (this file will be included by default by the compiler) and added the following declaration to it:
declare var process: any;
Hope it helps! :)

vmc push Errno::ENOENT: No such file or directory

I am trying to deploy this example to Cloud Foundry
https://github.com/andris9/Nodemailer/blob/master/examples/example_smtp.js
Here is what I did:
npm install nodemailer
Rename example_smtp.js to app.js and edit fields for right email credential
Tested node app.js locally and it works / email sent
vmc push and got below error
Uploading mytestmailer... FAILED Upload failed. Try again with 'vmc
push'. Errno::ENOENT: No such file or directory -
C:/Users/username/AppData/Local/Temp/.
vmc_hocmailer_files/node_modules/nodemailer/node_modules/simplesmtp/node_modules
/xoauth2/node_modules/request/node_modules/form-data/node_modules/combined-strea
m/node_modules/delayed-stream/test/integration/test-delayed-http-upload.js
For more information, see ~/.vmc/crash
I search and found this thread to figure out what is in ~/.vmc/crash
how to access ~/.vmc/crash folder on Cloud foundry
But I am using Windows so I cannot find that crash file.
Can someone help me to troubleshoot this issue? Seem to be a simple deployment.
You need to make sure you create a package.json file that specifies the dependencies of the application, in this case it should look something like this;
{
"name": "node-mailer-example",
"version": "0.0.1",
"dependencies": {
"nodemailer": "*"
}
}
With nothing but this and app.js in the folder, install the dependencies for the application with npm;
npm install
This should create a new 'node_modules' folder with the dependencies included inside.
Also, you need to change the first line of your app.js file so it reads;
var nodemailer = require('nodemailer');
I did it like this and it deployed ok, I got this message in the application log;
SMTP Configured
Sending Mail
Error occured
Invalid login - 535-5.7.1 Please log in with your web browser and then try again. Learn more at
535 5.7.1 https://support.google.com/mail/bin/answer.py?answer=78754 hr1sm24898342qeb.3 - gsmtp
BTW, when you send mail on mass through gMail, where each e-mail has the same content, gMail will eventually require you log in via the web interface before you can continue.

Resources