【问题标题】:How to fix 'require(...).config(...) is not a function' error when requiring dotenv如何在需要 dotenv 时修复“require(...).config(...) 不是函数”错误
【发布时间】:2021-07-08 03:08:06
【问题描述】:

我在使用 dotenv 时遇到了这个错误:

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

在我需要 dotenv 之前,Evertyghing 工作正常。

这是代码

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

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

【问题讨论】:

    标签: node.js typeerror puppeteer require dotenv


    【解决方案1】:

    看来你只是漏掉了这行后面的分号:

    require('dotenv').config()
    

    所以解析器将下一行的括号解析为函数调用。

    【讨论】:

    • 天哪,你是对的。这么小的一个小错误。谢谢。
    猜你喜欢
    • 2020-06-14
    • 1970-01-01
    • 1970-01-01
    • 2019-12-25
    • 2023-03-03
    • 2021-06-12
    • 2019-07-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多