Skip to content

Lucee throws error accessing this.env in config/app.cfm for new applications #2325

Closed

Description

@zainforbjs

Describe the bug
When running a newly created Wheels application on Lucee, an error is thrown indicating that this.env is not accessible within config/app.cfm.

The application fails with the following error:

Component [Application] has no accessible Member with name [ENV]
Detail: enable [trigger data member] in administrator to also invoke getters and setters

This occurs when attempting to access environment variables using this.env inside config/app.cfm.

Stacktrace (relevant part):

C:\inetpub\wwwroot\wheels\config\app.cfm: line 37
if (structKeyExists(this.env, "WHEELS_ENV") && this.env.WHEELS_ENV == "development"){

To Reproduce
Steps to reproduce the behavior:

  1. Create a Wheels application and configure .env and .env.development files with the datasource and environment variables.
  2. Start the application and open it in a browser.
  3. Observe the error related to this.env.

*Code Sample
config/app.cfm):

<cfscript>
this.name = "demoapp";
if (structKeyExists(this.env, "WHEELS_ENV") && this.env.WHEELS_ENV == "development"){
    this.datasources[this.env.DS_NAME] = {
        class: "com.mysql.cj.jdbc.Driver",
        connectionString: "jdbc:mysql://#this.env.DS_HOST#:#this.env.DS_PORT#/#this.env.DB_DATABASE#?serverTimezone=UTC",
        username: "#this.env.DB_USER#",
        password: "#this.env.DB_PASSWORD#"
    };
}
</cfscript>

Environment Variables:
.env

WHEELS_ENV=development
WHEELS_CI=true
BASE_URL=http://127.0.0.1:8080

.env.development

WHEELS_ENV=development
DS_NAME=demoapp
DS_HOST=localhost
DS_PORT=3306
DS_DATABASE=demoapp
DS_USER=root
DS_PASSWORD=root

Expected behavior
Environment variables defined in .env files should be accessible via this.env inside config/app.cfm without requiring additional Lucee administrator configuration.

Actual behavior
Lucee throws an error indicating that this.env is not accessible, preventing the application from starting.

Possible cause
The issue appears to be caused by the execution order in Application.cfc, where config/app.cfm is included before the environment variables (this.env) are initialized.
Specifically:

  • The following block was recently introduced and runs early in the application lifecycle:
if (FileExists(expandPath("../config/app.cfm"))) {
    include "../config/app.cfm";
}
  • At this point, this.env has not yet been created or populated, since the environment-loading logic executes later in the file.
  • As a result, when config/app.cfm tries to access this.env, Lucee throws:
Component [Application] has no accessible Member with name [ENV]

Screenshots
Image

Desktop:

  • OS: Any

Additional context

  • config/app.cfm is included again later (after this.env is initialized), which suggests that the earlier inclusion is redundant and occurs prematurely.
  • In previous behavior, config/app.cfm was only executed after environment setup, so this.env was always available.

Activity

  1. bpamiri commented on Apr 28, 2026

    @bpamiri
    Collaborator

    I tried to reproduce on macOS arm64 + Lucee 7.0.0.395 with the latest develop (post-#2348). The pattern from your repro:

    <cfscript>
    this.name = "demoapp";
    if (structKeyExists(this.env, "WHEELS_ENV") && this.env.WHEELS_ENV == "development"){
        // ...
    }

    …runs cleanly here — no Component [Application] has no accessible Member with name [ENV] error. Looking at the framework's cli/lucli/templates/app/public/Application.cfc:49-85, this.env is initialized in the pseudo-constructor before include "../config/app.cfm" runs at line 89, so the access ought to be safe.

    A few questions to narrow the gap so we can patch it properly:

    1. Lucee version — wheels info or /wheels/info reports it. The error wording (enable [trigger data member]) is a Lucee 5/6 era message; Lucee 7 reports differently. Knowing your exact Lucee version would help.
    2. Framework version — same source. The this.env setup block was added relatively recently; older framework copies may not have it.
    3. Custom Application.cfc? — does your app at C:\inetpub\wwwroot\wheels\Application.cfc match the template exactly, or have local edits? If it's a custom one without the lines 49–85 setup block, this.env would never be initialized.
    4. Was the app scaffolded with wheels new or a different command? Older wheels init/init paths produced different Application.cfc layouts.

    Happy to dig deeper once we have those — easiest path is probably to add a defensive guard at the top of config/app.cfm so user code is robust regardless of framework lifecycle.

  2. zainforbjs commented on Apr 29, 2026

    @zainforbjs
    ContributorAuthor

    Thanks for digging into this.

    I think I’ve identified why we’re seeing different behavior.

    I created the application using the wheels new CLI command, and it generated an Application.cfc based on:

    In this version, config/app.cfm is included early:

    if (FileExists(expandPath("../config/app.cfm"))) {
    	include "../config/app.cfm";
    }
    

    At this point, this.env has not yet been initialized, which leads to:

    Component [Application] has no accessible Member with name [ENV]
    

    However, the file you referenced:

    • cli/lucli/templates/app/public/Application.cfc (lines 49–85)

    initializes this.env before including config/app.cfm, so the same code works correctly there.

    So it looks like the CLI is currently scaffolding the app using a different (or outdated) Application.cfc compared to the template you tested against.

    That mismatch seems to be the root cause of the issue on my side.

  3. added
    LuCLI-upstreamTracked here but belongs upstream in bpamiri/LuCLI (issues disabled there)
    phase:1-stabilizeBugs, cleanup, CI fixes — tackle first
    and removed
    LuCLI-upstreamTracked here but belongs upstream in bpamiri/LuCLI (issues disabled there)
    on Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugphase:1-stabilizeBugs, cleanup, CI fixes — tackle first

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions