【问题标题】:Import {functionName} is undefined in list of functions built at runtime导入 {functionName} 在运行时构建的函数列表中未定义
【发布时间】:2018-05-25 20:36:37
【问题描述】:

一个函数在运行时收集其他函数以导出:

const list = getFunctions();

其中const list 是一个包含函数的对象:

{
 f1: function1,
 f2: function2,
 f3: function3
}

然后我导出函数对象:

export { list };

并将其中一个函数导入另一个文件:

import { f1 } from './functionsList';

f1 未定义。

【问题讨论】:

  • 你添加了一些不必要的步骤:export const list = getFunctions();
  • @TheIncorrigible1 我将您的建议用于export const list,但它仍然未定义。我试过import { list } from './functionsList',它显示了函数列表。这是否意味着 const 本身正在被导出?
  • 如果我理解正确,是的。 I'd ultimately defer to the documentation here

标签: javascript ecmascript-6 es6-modules


【解决方案1】:

我使用了 module.exports 的解决方法:

module.exports = list;

import { f1 }合作

发件人:https://stackoverflow.com/a/40704948/665082

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-04
    • 2018-02-05
    • 1970-01-01
    • 1970-01-01
    • 2020-05-12
    • 2021-04-15
    • 2017-11-14
    • 1970-01-01
    相关资源
    最近更新 更多