简体   繁体   中英

Node.js and requirejs undefined

I really tried to find the solution on the stackoverflow and google

but I could not find any clear solution.

I am a student and try to make a web application with

js, node.js, bootstrap, firebase, css

actually when I tried to use do something like var firebase = require('firebase');

I always get the message "require is undefined"

these are my package.json

{
  "name": "recette",
  "version": "1.0.0",
  "description": "Recette BCIT GROUP 22 Project",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/lewisfang59/recette.git"
  },
  "author": "Group22",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/lewisfang59/recette/issues"
  },
  "homepage": "https://github.com/lewisfang59/recette#readme",
  "dependencies": {
    "@sendgrid/mail": "^6.2.1",
    "nodemailer": "^4.6.4"
  }
}

and this is the code that I wanted to use require

// using SendGrid's v3 Node.js Library
// https://github.com/sendgrid/sendgrid-nodejs
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
  service: 'gmail',
  auth: {
    user: 'xx@gmail.com',
    pass: 'xxx'
  }
});

var mailOptions = {
  from: 'recette.group22@gmail.com',
  to: 'hwan5263@gmail.com',
  subject: 'Sending Email using Node.js',
  text: 'That was easy!'
};

transporter.sendMail(mailOptions, function(error, info){
  if (error) {
    console.log(error);
  } else {
    console.log('Email sent: ' + info.response);
  }
});

this is the code for firebase, same issue.

var firebase = require('firebase');
// Initialize Firebase
var config = {
    apiKey: "0",
    authDomain: "recmoved",
    databaseURL: "removed!",
    projectId: "foodver",
    storageBucket: "foo",
    messagingSenderId: "22300"
};
firebase.initializeApp(config);

var db = firebase.firestore();

I am very new to this area. Please tell me anything I need to add more!

thank you so much!!

require is not available in the browser.

As mentioned by others, consider introducing a build system like Webpack. RequireJS may also be an option for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM