gpt4 book ai didi

javascript - 将数组导出为 es6 模块

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:53:59 25 4
gpt4 key购买 nike

出于某种原因,我无法使用作为 es6 模块导出的数组:

export const choices = [
['first', 'First'],
['second', 'Second'],
['third', 'Third'],
]

然后:

import { choices } from './constants'
console.log(choices) // undefined

如果我只是在尝试使用它的同一个文件中声明 const,它会按预期工作。

最佳答案

浏览器上下文中的模块使用相对 URL,包括扩展名。所以导入应该是 from './constants.js' 而不仅仅是 from './constants'。 (不过,后者在 Node.js 上会很好,因为它具有当前实验性的模块支持。)

关于javascript - 将数组导出为 es6 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51082786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com