【问题标题】:Convert CommonJS require statement to load via an ES6 import?转换 CommonJS 要求语句以通过 ES6 导入加载?
【发布时间】:2020-04-23 20:13:22
【问题描述】:

我想将此 CJS 要求语句转换为通过 ES 模块导入加载。 (我的 package.json 中已经有 type: 'module')

var https = require('https').globalAgent.options.ca = require('ssl-root-cas/latest').create();

【问题讨论】:

  • ssl-root-cas/latest 似乎没有使用 ES6 导出。您使用的是什么转译器解决方案?
  • 我正在使用我认为使用 webpack 的 next.js

标签: es6-modules commonjs


【解决方案1】:

这可以通过...来实现

import sslrootcas from 'ssl-root-cas';
https.globalAgent.ca = sslrootcas.create();

但我想知道 ES 模块是否有类似 CJS 的单线方法?

【讨论】:

    猜你喜欢
    • 2019-12-18
    • 2016-08-31
    • 2020-01-11
    • 1970-01-01
    • 2017-07-23
    • 1970-01-01
    • 1970-01-01
    • 2022-06-17
    • 1970-01-01
    相关资源
    最近更新 更多