Next.js's loadEnvConfig fails to load environment variables in Cypress' support file

Viewed 534

I need some of the environment variables from my Next.js project in my Cypress tests and it seems that the proper way to do that is to use loadEnvConfig from @next/env.

Cypress enables a way to run code before each test via its support file.

This is what my support file looks like:

import { loadEnvConfig } from '@next/env'
import './commands'

loadEnvConfig('/path/to/my/project')

When I run Next in dev mode and then Cypress I get the following errors in the console:

index.js:1 Failed to load env from .env.production.local TypeError: t.statSync is not a function
    at loadEnvConfig (index.js:1)
    at Object../cypress/support/index.js (index.js:4)
    at __webpack_require__ (bootstrap:19)
    at Object.0 (tests?p=cypress/support/index.js:682)
    at __webpack_require__ (bootstrap:19)
    at eval (bootstrap:83)
    at eval (bootstrap:83)
    at eval (<anonymous>)

There are three more similar ones, for .env.local, .env.production, and .env.

0 Answers
Related