• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

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

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.

almost 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error