Skip to content

environment undefined first time through #7779

Closed

Description

@jamesarosen

I've added the following to my config/environment.js:

console.log('environment', environment)

When I run ember serve, I see

environment undefined
Could not start watchman
Visit https://ember-cli.com/user-guide/#watchman for more info.
environment development

That is, config/environment.js gets called multiple times (at least once to boot the server and once per middleware), but environment only gets defaulted to 'development' after the first invocation.

Output from ember version --verbose && npm --version && yarn --version:

ember-cli: 3.1.0-beta.1
http_parser: 2.7.0
node: 6.9.1
v8: 5.1.281.84
uv: 1.9.1
zlib: 1.2.8
ares: 1.10.1-DEV
icu: 57.1
modules: 48
openssl: 1.0.2j
os: darwin x64
5.5.1
1.3.2

Activity

  1. changed the title [-][2.18.2] environment undefined first time through[/-] [+]environment undefined first time through[/+] on Apr 19, 2018
  2. rwjblue commented on Apr 19, 2018

    @rwjblue
    Member

    The argument passed in to your config/environment.js function is ultimately supplied by the caller of project.config(environmentStringHere). If anyone is calling project.config() (without an arg) then you will have your function's first argument be undefined.

  3. jamesarosen commented on Apr 19, 2018

    @jamesarosen
    Author

    Bingo! https://github.com/ember-cli/ember-resolver/blob/d37c06bd37eb08363dcd1cc5e6ab4329190552b1/index.js#L11

    So is that "supported" behavior? If so, is the meaning of that call something like "project configuration that is not environment-dependent"?

  4. givanse commented on May 22, 2018

    @givanse

    There is a report of environment being undefined here.

    And I saw the same behavior in a brand new app. (I incorrectly reported it here first In config/environment.js the value of environment is undefined)

     ember-cli: 2.18.2
     node: 8.11.2
     os: win32 x64
    

    logs environment as undefined

  5. givanse commented on May 22, 2018

    @givanse

    I did some digging, looks like commandArgs is no longer consumed in lookup-command (unused variable) And maybe that is why the resolver is not getting it? (plus missing arg in config call)

    Another observation I made is that if I execute: ember build --environment=fizzbuzz, when logging the environment variable in config/environment.js, I'll see:

    undefined
    fizzbuzz
    test
    
  6. rwjblue commented on May 22, 2018

    @rwjblue
    Member

    The environment argument passed to config/environment.js is whatever is passed to project.config. I suspect it is undefined because it is being called as project.config() instead of as project.config(someValue).

    In the past this was due to ember-resolver calling project.config() in its init (so it could see if the module unification feature flag was enabled), but as of a change on master here we should be checking for process.env.EMBER_CLI_MODULE_UNIFICATION and can likely remove the config lookup...

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions