0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PlatformIOのNameError: name 'includes' is not defined

0
Posted at

概要

VSCodeでM5Stackなどの開発に使うPlatformIO起動時に以下のエラーが出るのを解消します。

  • Windows 11 Pro 25H2
  • VSCode 1.135.0
  • PlatformIO 6.1.19
Resolving m5stack-core2 dependencies...
Already up-to-date.
Updating metadata for the vscode IDE...
NameError: Traceback (most recent call last):
  File "C:\Users\nobrin\.platformio\penv\Lib\site-packages\platformio\__main__.py", line 103, in main
    cli()  # pylint: disable=no-value-for-parameter
    ^^^^^

...(省略)

  File "<string>", line 75, in <module>
NameError: name 'includes' is not defined

調べると、いろいろと原因は書かれていますが、私の場合は全然解決しませんでした。
(.pio削除やPlatformIO再インストールなど)

結局、環境変数 PLATFORMIO_BUILD_DIR${PROJECT_HASH} が原因でした。より正確にはPlatformIOのWorkspaceDirまわりに ${PROJECT_HASH} を使うとダメっぽいということした。

以下のように ${PROJECT_HASH}${platformio.name} などに変更するとエラーは解消されます。

  • NG
PLATFORMIO_BUILD_DIR = ${sysenv.TEMP}/PlatformIO/BuildDir/${PROJECT_HASH}
  • OK
PLATFORMIO_BUILD_DIR = ${sysenv.TEMP}/PlatformIO/BuildDir/${platformio.name}

環境変数 PLATFORMIO_BUILD_DIR ではなく、platformio.ini 中の [platformio] -> build_dir または workspace_dir でも同様のことが起こります。解決方法は同様に ${PROJECT_HASH} を変更することです。

詳細

ソースファイルなどはGoogle Driveディレクトリ、ビルドディレクトリは別のローカルディレクトリ、という設定を行っていた影響でエラーが発生していました。
ネットにある情報だと、テンプレートなどの不整合が原因とかかれているので、全然解決にたどり着きませんでした…。ダメ元でChatGPTでステップバイステップでちょっと丁寧に確認しながら進めて行ったところ、ようやく解消することができました。

正確には PROJECT_HASHplatformio.name は同じではありません(PROJECT_HASHはプロジェクト名+サフィックス)。
ですので、同名のプロジェクトを扱う場合は platformio.ini[platformio] セクションに name で定義することで、その値が使用されます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?