Search code examples
node.jstypeerrorpuppeteerrequiredotenv

How to fix 'require(...).config(...) is not a function' error when requiring dotenv


I am getting this error with dotenv:

(async () => {
^
TypeError: require(...).config(...) is not a function

Evertyghing was working fine until I required dotenv.

This is the code

const puppeteer = require('puppeteer');
const fs = require('fs');
require('dotenv').config()

(async () => {
  const browser = await puppeteer.launch({
    headless: false,
    args: ['--start-maximized'],
    defaultViewport: null,
  });

  const page = await browser.newPage();
  ...more code here
})()

Dotenv is properly installed:

  "dependencies": {
    "dotenv": "^8.2.0",
    "puppeteer": "^5.3.1"
  }

Solution

  • It seems you just missed the semicolon after this line:

    require('dotenv').config()
    

    So parser parses the parenthesis in the next line as a function call.