Cannot read properties of undefined (reading 'id')

Hi,
I’m using PlatformIO for developing a project whit an RP2040 and an ESP01 connected to it.

So I’ve created multiple environments for differentiating sources, such functionality testing files and real application sources, but also for sources for the ESP01 and the RP2040:

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[platformio]
extra_configs = upload_port.ini
default_envs = pico

[env]
extra_scripts = pre:git_script.py

[env:pico]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = pico
framework = arduino
board_build.mcu = rp2040
board_build.core = earlephilhower
monitor_speed = 115200
build_src_filter = -<ESP>

[env:test_WebServer]
extends = env:pico
build_src_filter =  -<./main.cpp>
                    +<./common>
                    +<../testing/test_WebServer>
lib_deps =  https://github.com/adafruit/Adafruit-GFX-Library.git#126007f
            https://github.com/adafruit/Adafruit_SSD1306.git#7a4d33e
            https://github.com/adafruit/Adafruit_NeoPixel.git@1.12.0

[env:esp]
framework = arduino
monitor_speed = 115200
board_build.filesystem = littlefs
build_src_filter =  -<.>
                    +<ESP>
lib_deps = https://github.com/cotestatnt/esp-fs-webserver.git#1.2.7

[env:esp01]
extends = env:esp
platform = espressif8266@4.2.1
board = esp01


[env:esp32]
extends = env:esp
platform = espressif32@6.4.0
board = esp32dev

and it’s ok, but when I change the environment buttons in the bottom navigation tab:

shows the Cannot read properties of undefined (reading 'id') error and for upload/build/etc… I have to use the PlatfomIO tab on the nav bar instead:

[EDIT]:
I’m working on Windows 10 and VSCode 1.86.1 and PIO (core: 6.1.14) (Home: 3.4.4)

There is any solution?? This is very uncomfortable…

Thanks in advance!
Alan

1 Like

Due to you not having posted the upload_port.ini and git_script.py file, I can’t 100% reproduce your platformio.ini, only with commenting those out.

Clicking on the checkmark icon with the test_Webserver environment selected does perform a normal build.

When I change the environment to e.g., pico, and wait for the

grafik

load message to disappear, and click the checkmark again, it again performs a normal build.

This, I can’t reproduce the error you’re having with this.

Hi and thanks for your reply,
the problem which I found is caused when you try to compile whit another environment, so before reproducing my specific configuration, if you could, try to compile whit another environment.

Another hint before testing my config is about the .vscode/lounch.json that I think is not overwritten when the environment changes getting the configuration error!

Anyway, this are the sources your are asking for:
in the upload_port.ini I set up only the upload port for environments whit:

[env:pico]
upload_port = COM19
monitor_port = COM19

[env:esp01] 
upload_port = COM18
monitor_port = COM18

[env:esp32]
upload_port = COM10
monitor_port = COM19

and this is my solution for avoid to track whit git the COM port selected each time (that for Win world is COM and in linux OS is /dev/… so, since I’m working with classmates, I would like to not track this information) (and I also hope is it the correct way for doing it, if not I grateful of having a better solution)

the git_script is the following:

import subprocess
import os


# Crea il file git_revision.h
f = open("include/git_revision.h", "w")

local_path = os.path.abspath(".")
local_path = local_path.replace("\\", "/")

# Controlla se la cartella corrente è un repository git
try:
    subprocess.check_output(["git", "rev-parse", "HEAD"])
    is_git_repo = True
except subprocess.CalledProcessError:
    is_git_repo = False

# Se è un repository git, prendi l'ID del commit più recente
if is_git_repo:
    log_command = ["git", "log", "--oneline"]
    try:
        output = subprocess.check_output(log_command, universal_newlines=True)
        commits = output.strip().split('\n')

        if commits:
            # Se ci sono commit, prendi l'ID del commit più recente
            latest_commit_id = commits[0].split()[0]

            # Salva l'ID del commit su un file
            f.write("#ifndef __GIT_COMMIT__\n")
            f.write("#define __GIT_COMMIT__ \"%s\"\n" % latest_commit_id)
            f.write("#endif\n")

            # Verifica se esiste una repository remota
            remote_url_command = ["git", "config", "--get", "remote.origin.url"]
            try:
                remote_url = subprocess.check_output(remote_url_command, universal_newlines=True).strip()
                f.write("#ifndef __GIT_REMOTE_URL__\n")
                f.write("#define __GIT_REMOTE_URL__ \"%s\"\n" % remote_url)
                f.write("#endif\n")
            except subprocess.CalledProcessError:
                f.write("#ifndef __GIT_REMOTE_URL__\n")
                f.write("#define __GIT_REMOTE_URL__ \"L:%s\"\n" % local_path)
                f.write("#endif\n")

        else:
            f.write("#ifndef __GIT_COMMIT__\n")
            f.write("#define __GIT_COMMIT__ \"NO_COMMITS_YET\"\n")
            f.write("#endif\n")
            # Remote URL
            f.write("#ifndef __GIT_REMOTE_URL__\n")
            f.write("#define __GIT_REMOTE_URL__ \"L:%s\"\n" % local_path)
            f.write("#endif\n")
    except subprocess.CalledProcessError:
        f.write("#ifndef __GIT_COMMIT__\n")
        f.write("#define __GIT_COMMIT__ \"SCRIPT_ERROR\"\n")
        f.write("#endif\n")
        # Remote URL
        f.write("#ifndef __GIT_REMOTE_URL__\n")
        f.write("#define __GIT_REMOTE_URL__ \"L:%s\"\n" % local_path)
        f.write("#endif\n")
else:
    f.write("#ifndef __GIT_COMMIT__\n")
    f.write("#define __GIT_COMMIT__ \"NO_REPO\"\n")
    f.write("#endif\n")
    # Remote URL
    f.write("#ifndef __GIT_REMOTE_URL__\n")
    f.write("#define __GIT_REMOTE_URL__ \"L:%s\"\n" % local_path)
    f.write("#endif\n")

# Chiudi il file
f.close()

# .gitignore update
gitignore = open(".gitignore", "r")
if "git_revision.h" not in gitignore.read():
    gitignore.close()
    gitignore = open(".gitignore", "a")
    gitignore.write("git_revision.h\n")
    gitignore.close()

So another time thanks for your time and support,

Alan

If upload_port is not selected at all, PlatformIO will do its best to automatically detect the right upload port, based on existing upload ports and matching of the USB VID:PID pair if existing in the board definition. So unless that absolutely didn’t work, I would actually delete that part.

It should change. In the section

    "configurations": [
        {
            "type": "platformio-debug",
            "request": "launch",
            "name": "PIO Debug",
            "executable": "c:/Users/Max/temp/pico_first/.pio/build/pico/firmware.elf",

the path to the executable should change to the new environment’s name, in thise case pico, to the new selected environment.

Have you already tried to disable all VSCode extensions but PlatformIO, C/C++ and Python, to avoid any possibly cross-contamination from other extensions?

If you take a look on the ESP32 env, the upload_port and the monitor_port are different also for specific purposes (the ESP32 is connected to the PC through USB and also to an RP2040 using UART, so what I have to check in this case is the UART part so, the RP2040, echoes also the ESP serial data)

No, I don’t… there is a way for doing it in a fast way?

[edit]

It should change automatically??

Alan

I’m having this behavior as well, already for several months. Here is what’s happening:

  • after switching the [env] there is some activity from PlatformIO extension, showing a clock badge on the PlatformIO icon in the left-side taskbar.
  • if you try to build before this activity is completed, you get the Cannot read properties of undefined (reading ‘id’) error. That’s ok, it’s busy.
  • after some time working (typically a few hours), even if you wait until the environment switching activity is completed, this error also pops up. It only pops up when using the bottom toolbar. When using the left-side bar (Project Tasks), it still works. The problem is not only for build, also for test.
  • when you exit VSCode and re-open it, the bottom toolbar works again.

So currently my workaround is to close VSCode and open it again, but still it is an annoying thing.

My setup is Win11 and all up-to-date with PlatformIO.

My repo is this : Strooom/MuMo-v2-Node-SW: Firmware for the Museum Monitor V2 node (github.com) in case you want to check my platformio.ini

Very interesting that this is reproducable for a second person. Can you file that in https://github.com/platformio/platformio-vscode-ide/issues? Only way to get developer attention.

Here is the Issue opened.

Thanks for help!
Alan

Hi. Same thing happening here.

As strooom, when I close VSCode and open it again and it’s working .

@alanmasu @udem1234

I’ve published a possible solution here

TLDR: Conflict with other Extension (CMake in my case)