Dotenv module doesn't work with cypress
See original GitHub issue- Operating System: Windows 10
- Cypress Version: 1.4.2
- Browser Version: Chrome 63
Bug
Current behavior:
https://www.npmjs.com/package/dotenv In order to use this module to have to require(‘dotenv’). If I do this anywhere in code it fails:
./node_modules/dotenv/lib/main.js
Module not found: Error: Can't resolve 'fs' in '<project dir>\node_modules\dotenv\lib'
resolve 'fs' in '<project dir>\node_modules\dotenv\lib'
Parsed request is a module
using description file: <project dir>\node_modules\dotenv\package.json (relative path: ./lib)
Field 'browser' doesn't contain a valid alias configuration
after using description file: <project dir>\node_modules\dotenv\package.json (relative path: ./lib)
resolve as module
<project dir>\node_modules\dotenv\lib\node_modules doesn't exist or is not a directory
<project dir>\node_modules\dotenv\node_modules doesn't exist or is not a directory
<project dir>\node_modules\node_modules doesn't exist or is not a directory
<project dir>\node_modules doesn't exist or is not a directory
<user dir>repo\node_modules doesn't exist or is not a directory
<user dir>repo\node_modules doesn't exist or is not a directory
C:\Users\node_modules doesn't exist or is not a directory
C:\node_modules doesn't exist or is not a directory
looking for modules in <project dir>\node_modules
using description file: <project dir>\package.json (relative path: ./node_modules)
Field 'browser' doesn't contain a valid alias configuration
after using description file: <project dir>\package.json (relative path: ./node_modules)
using description file: <project dir>\package.json (relative path: ./node_modules/fs)
no extension
Field 'browser' doesn't contain a valid alias configuration
<project dir>\node_modules\fs doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
<project dir>\node_modules\fs.ts doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
<project dir>\node_modules\fs.js doesn't exist
as directory
<project dir>\node_modules\fs doesn't exist
looking for modules in <user dir>node_modules
No description file found
Field 'browser' doesn't contain a valid alias configuration
No description file found
no extension
Field 'browser' doesn't contain a valid alias configuration
<user dir>node_modules\fs doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
<user dir>node_modules\fs.ts doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
<user dir>node_modules\fs.js doesn't exist
as directory
<user dir>node_modules\fs doesn't exist
[<project dir>\node_modules\dotenv\lib\node_modules]
[<project dir>\node_modules\dotenv\node_modules]
[<project dir>\node_modules\node_modules]
[<project dir>\node_modules]
[<user dir>repo\node_modules]
[<user dir>repos\node_modules]
[C:\Users\node_modules]
[C:\node_modules]
[<user dir>node_modules\package.json]
[<project dir>\node_modules\fs]
[<project dir>\node_modules\fs.ts]
[<user dir>node_modules\fs\package.json]
[<project dir>\node_modules\fs.js]
[<user dir>node_modules\fs]
[<project dir>\node_modules\fs]
[<user dir>node_modules\fs.ts]
[<user dir>node_modules\fs.js]
[<user dir>node_modules\fs]
@ ./node_modules/dotenv/lib/main.js 3:11-24
@ ./dist/specs/menu.spec.js
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Cypress can't get variables from process.env file
I've got a problem with getting variables value from process.env file in my cypress test. I try to do it according to this: ......
Read more >Environment Variables | Cypress Documentation
Difference between OS-level and Cypress environment variables In Cypress, "environment variables" are variables that are accessible via Cypress.env.
Read more >Cypress v10 Environment Variables - Gleb Bahmutov
module.exports = defineConfig({ // our project does not use fixture files fixturesFolder: false, env: { // user values block 1 level: 1,
Read more >Env Variables and Modes - Vite
For example, dynamic key access like import.meta.env[key] will not work. It will also replace these strings appearing in JavaScript strings and Vue templates....
Read more >types/cypress-dotenv - NPM Package Overview - Socket.dev
Start using Socket to analyze @types/cypress-dotenv and its 1 dependencies to secure your ... Problems with the package may go unaddressed.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
for someone who will be looking for working examples:
You cannot require npm modules which use native node libs like
fs
. Cypress serves your JS spec files to the browser - the usage offs
makes no sense there.If you want to read in config files and then set env vars into Cypress you can use the Configuration Plugin API to do just that.
Files you write in the
plugins
folder are evaluated bynode
, not the browser - which is just the place to use them.https://docs.cypress.io/api/plugins/configuration-api.html#