类型错误:分配给 const 变量,将变量声明为 let (在 config.js 文件中并导出到另一个文件 index.js

问题描述 投票:0回答:1

在 javascript(node JS) 中,我制作了一个如下所示的 config.js 文件,用于导出名称变量

配置.js

导出让名称=“ayush”;

我正在index.js 文件中导入 name 变量

index.js

从“./config.js”导入{name};

名称=“Rishabh”

console.log(名称);

但是我收到类型错误:赋值给常量变量。

我已经将变量声明为 Let ,那么为什么我仍然遇到上述错误。

我正在尝试更改另一个文件中的变量名称。但我收到错误,无法理解缺少什么 javascript 概念(导入仅是只读的)。

javascript node.js
1个回答
0
投票

这样做是为了

Config.js

export let config = {
  name: "ayush"
};

然后这样做

index.js

import { config } from "./config.js";

config.name = "Rishabh"; // modify the property of the object

console.log(config.name); // logs "Rishabh"

试试这个我希望它会起作用。

© www.soinside.com 2019 - 2024. All rights reserved.