-1
const nodemailer = require('nodemailer');
const { google } = require('googleapis');

I wrote the code for lessons on the Internet for the node js. But I need to do this for the site so I copied it. After running it gave me this problem (not with command node app.js, it starts in browser as default js code): Uncaught ReferenceError: require is not defined. Please tell me what can be done.

  • 1
    Does this answer your question? [Client on Node.js: Uncaught ReferenceError: require is not defined](https://stackoverflow.com/questions/19059580/client-on-node-js-uncaught-referenceerror-require-is-not-defined) – grekier Aug 02 '21 at 22:23
  • 1
    Check out this question/answer: https://stackoverflow.com/a/19059825/1540177 – grekier Aug 02 '21 at 22:24

1 Answers1

0

In web browser we don't have the require function.

You can use the import statement or use cdn services like that:

<script src="https://apis.google.com/js/api.js"></script>

importing directly like:

import { google } from 'googleapis';

won't work on web browsers because the browser does not know where 'googleapis' is.

Neriya Cohen
  • 150
  • 8