首页 > 解决方案 > babel-jest 找不到 https

问题描述

我正在使用 jest/babel-jest 编写节点应用程序,正在使用https模块。

babel.config.js

module.exports = {
  presets: [
    [
      '@babel/preset-env',
      {
        targets: {
          node: 'current',
        },
      },
    ],
  ],
};

测试文件:

import { https } from 'https';

// do some stuff

https.request(...);

但是当我开玩笑时,我得到了这个:

TypeError: Cannot read property 'request' of undefined

为什么不让我发出 http 请求?

我知道我在做一些愚蠢的事情,我只是不知道是什么:P

标签: node.jsjestjs

解决方案


尝试

import https from 'https';

推荐阅读