Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build failed with error Cannot assign to "envs" because it is a constant. #2938

Open
restarbuck101 opened this issue Apr 4, 2024 · 1 comment
Assignees
Labels

Comments

@restarbuck101
Copy link

Describe the bug
Build failed with error Cannot assign to "envs" because it is a constant script:/home/geeseman/caldera/plugins/magma/src/plugins/builder/views/builder.vue?id=0:9:4: ERROR: Cannot assign to "envs" because it is a constant vite v2.9.15 dev server running at:
The issue arises from attempting to reassign a value to a constant variable that was intended to be a reactive reference.

To Reproduce
Executing Caldera with the following 4 commands in your terminal.
1.git clone https://github.com/mitre/caldera.git --recursive
2.cd caldera
3.pip3 install -r requirements.txt
4.python3 server.py --insecure --build

Expected behavior
The expected behavior was that the envs reactive reference would be updated with the new value fetched from $api.get("/plugin/builder/environment"), allowing the component to react to the updated state. The process should not result in build errors, and the development server should start without issues.

Screenshots
Build failed with 2 errors:
script:/caldera/plugins/builder/gui/views/builder.vue?id=0:9:4: ERROR: Cannot assign to "envs" because it is a constant script:/home/geeseman/caldera/plugins/magma/src/plugins/builder/views/builder.vue?id=0:9:4: ERROR: Cannot assign to "envs" because it is a constant vite v2.9.15 dev server running at: > Local: http://localhost:3000/

Network: http://10.2.0.7:3000/

ready in 261ms.

✘ [ERROR] Cannot assign to "envs" because it is a constant

script:/home/caldera/plugins/magma/src/plugins/builder/views/builder.vue?id=0:9:4:
9 │     envs = await $api.get("/plugin/builder/environment");
	╵     ~~~~

The symbol "envs" was declared a constant here:

script:/home//caldera/plugins/magma/src/plugins/builder/views/builder.vue?id=0:5:6:
5 │ const envs = ref();
	╵       ~~~~

✘ [ERROR] Cannot assign to "envs" because it is a constant

script:/home/geeseman/caldera/plugins/builder/gui/views/builder.vue?id=0:9:4:
9 │     envs = await $api.get("/plugin/builder/environment");
	╵     ~~~~

The symbol "envs" was declared a constant here:

script:/home/caldera/plugins/builder/gui/views/builder.vue?id=0:5:6:
5 │ const envs = ref();
	╵       ~~~~

Desktop (please complete the following information):

  • OS: Debian 11
  • Browser: NA

Additional context
This issue is highlighted in both instances within your project's Vue component files:

/caldera/plugins/builder/gui/views/builder.vue
/caldera/plugins/magma/src/plugins/builder/views/builder.vue

Proposed solution:
Update a reactive reference by accessing its .value property, not by reassigning the reference itself. This approach adheres to the Vue.js Composition API's design, allowing you to maintain reactivity while conforming to JavaScript's const constraints.

For the builder.vue and any similar files , update the code as follows

Before:
const envs = ref();envs = await $api.get("/plugin/builder/environment");

After:
const envs = ref();envs.value = await $api.get("/plugin/builder/environment");

By modifying the code as suggested, you update the reactive state of envs without attempting to reassign the const, thereby avoiding the build errors.

Copy link

github-actions bot commented Apr 4, 2024

Looks like your first issue -- we aim to respond to issues as quickly as possible. In the meantime, check out our documentation here: http://caldera.readthedocs.io/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants