Run configurations with macro $ProjectFileDir$ do not work properly after starting the IDE/opening a new project

Answered

In our project, we are sharing run configurations via Git. These run configurations are part of one of our application's modules and get imported by IntelliJ IDEA automatically when a project with this module is opened.

This worked fine with 2021.3, but since 2022.1 and greater the run configurations get annotated with a red cross after Idea was started or the project was opened: 

This only happens with run configurations which contain the $ProjectFileDir$ macro. When opening these run configurations, the dialog complains that the directory containing the $ProjectFileDir$ macro does not exist:

The problem here is that the $ProjectFileDir$ variable does not seem to be assigned at this moment. In some cases, it was assigned but pointed to the project file directory of a different project that had been opened by the IDE before. (This can lead to very weird errors when the files of two different projects get mixed up.)

The only way we found to fix this is to click the "Insert Macros" icon

and press "Cancel" in the following dialog. Then Idea seems to remember the correct setting for the $ProjectFileDir$ macro and all the red crosses shown on the launch configurations disappear.

This is quite annoying as you have to do this each time you open the IDE or open a new project. And it is even more annoying as files of different projects can get mixed up when the $ProjectFileDir$ macro accidentally points to the project file directory of a different project so that the launch config of your current project A is using a working directory which belongs to project B.

2
7 comments

As a workaround, the path variable "$PROJECT_DIR$" worked for me.

0

Any of the solutions don't work, but I found a workaround, fill “.” and it works only if you start PhpStorm from the project directory ("cd /path/to/project && pstorm .").

Error i'm getting is "Error: Working folder '$ProjectFileDir$' not found"
 

PhpStorm 2025.1.3
Build #PS-251.26927.60, built on June 24, 2025

0

@Elan Ruusamäe Hi, what run configuration type (e.g. PHP Script) were you using when this issue occurred?

0

Lejia Chen I had "PHP Script" in this test, but top of my head, I recall having issues with PHPUnit too.

 

 

0
Ruusamäe Thanks for the info. The PHP related run configuration's working directory doesn't support macros currently.
I have created a feature request for you here: https://youtrack.jetbrains.com/issue/WI-82233/Support-macros-for-Custom-working-directory-in-PHP-related-run-configurations.

Feel free to vote on the issue to get updates. See [here](https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications) if you are not familiar with our issue tracker.
1

Please sign in to leave a comment.