gpt4 book ai didi

javascript - 是否可以在 babel 7 上解构导入?

转载 作者:行者123 更新时间:2023-12-03 00:11:34 26 4
gpt4 key购买 nike

使用 babel 7,您无法真正导出模块并再使用 babel 语法解构它们。是否有插件、旧语法或我缺少的东西可以让我执行以下操作?

// file1.js
export const x = 0;
export const y = 1;
export default z;

// file2.js
import { x, y } from './file1.js'
console.log(x); // output: 0
console.log(y); // output: 1

最佳答案

好的,我在 Felix 的帮助下解决了我的问题。我的误解非常愚蠢:export 仍然会声明您在其后定义的任何变量,例如:

const x = 0;
export const x = 0; // this will be invalid, because x is a constant already

我的 webpack 上不断出现语法错误,并且不明白这是因为我声明了两次变量,所以我认为这是 webpack 或 babel 的问题。

关于javascript - 是否可以在 babel 7 上解构导入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54702524/

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