简体   繁体   English

如何在需要 dotenv 时修复“require(...).config(...) 不是函数”错误

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

I am getting this error with dotenv:我收到 dotenv 的这个错误:

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

Evertyghing was working fine until I required dotenv.在我需要 dotenv 之前,Evertyghing 工作正常。

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: Dotenv 已正确安装:

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

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.因此解析器将下一行中的括号解析为 function 调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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