question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to use deeply nested config or env in plugins

See original GitHub issue

Current behavior:

When returning deeply nested config in the plugin, an error is shown on startup. “Unable to set property {propertyname} of undefined.”

Desired behavior:

When returning deeply nested config in the plugin, the config should be merged into the main config, and no error is shown.

Steps to reproduce:

Simply place the following in your plugins/index.js file.

module.exports = () => ({
  foo: {
    bar: 'baz',
  },
});

Versions

Cypress version 2.1.0

Other info

I did a little bit of digging and it tries to merge this extra config into “resolved” config but as cfg.resolved.foo doesn’t exist, it fails.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:11
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

17reactions
codybarrcommented, Aug 27, 2018

Yeah, I was trying to use separate config files per environment following the Config API docs here: https://docs.cypress.io/api/plugins/configuration-api.html#Promises

Nested values in my Cypress.json work fine, but when following the above pattern I’m also getting the same error:

image

Eg. We’re trying to use values like this:

// cypress/config/dev.json
{
    "baseUrl": "https://dev-website.com",
    "env":
    {
        "api": "https://api.dev-website.com",
        "users":
        {
            "admin":
            {
                "username": "admin",
                "password": "adminpassword"
            },
            "super":
            {
                "username": "super",
                "password": "superpassword"
            },
        }
    }
}
6reactions
mike-rogerscommented, Aug 1, 2018

In our app we needed to lean on node-config to deal with per-environment configurations. We ended up doing something like:

module.exports = (on, config) => {
    config.env.CONFIG = JSON.stringify(require('config'));
}

in plugins/index.js and something like:

    const config = JSON.parse(Cypress.env('CONFIG'));

in the tests. This approach seems to work fine for deeply nested structures.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using environment variables with Webpack
A guide for setting up and using environment variables with Webpack and handling ... Add it to the plugins in your webpack config...
Read more >
Environment Variables
Pain to write the --env options everywhere you use Cypress. No support for nested fields. Option #5: Test Configuration. You can set environment...
Read more >
You are reading environment variables the wrong way in ...
In a scenario where you build the application without having set the API_KEY environment variable the application will use undefined instead.
Read more >
Environment Variables - Cypress
It is a pain to write the --env options everywhere you use Cypress. It has no support for nested fields. Option #5: Plugins....
Read more >
dotenv file is not loading environment variables
Use only absolute path if you are using some other tool(installed globally) to call your config file somewhere .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found