Dotenv: fs.readFileSync is not a function error

Created on 6 Jul 2018  Â·  1Comment  Â·  Source: motdotla/dotenv

Hi,

I have installed and imported the 'dotenv' package but it doesn't seem to work.
I have included the below line in my entry file & I have .env file in the root directory :
require('dotenv').config();

When I debugged the code, in the node_modules/dotenv/lib/main.js file, there is a reference to ‘fs’ module and in line no.61, its failing with the below error :

TypeError: fs.readFileSync is not a function
at Object.config (main.js:61)
at Object../src/frt.js (frt.js:9)
at __webpack_require__ (bootstrap 69c22271b2f534682ec6:678)
at fn (bootstrap 69c22271b2f534682ec6:88)
at Object../src/App.js (App.css?9a66:26)
at __webpack_require__ (bootstrap 69c22271b2f534682ec6:678)
at fn (bootstrap 69c22271b2f534682ec6:88)
at Object../src/index.js (index.css?f255:26)
at __webpack_require__ (bootstrap 69c22271b2f534682ec6:678)
at fn (bootstrap 69c22271b2f534682ec6:88)
at Object.0 (index.js:7)
at __webpack_require__ (bootstrap 69c22271b2f534682ec6:678)
at ./node_modules/@emotion/hash/dist/index.es.js.__webpack_exports__.a (bootstrap 69c22271b2f534682ec6:724)
at bootstrap 69c22271b2f534682ec6:724

But when i installed fs module, it had nothing in it, per the npm site, this package is no longer used [https://www.npmjs.com/package/fs].

Could you please help solve this?

I'm running the below node and npm versions on Windows (x64).
Node JS version : 8.11.1
npm version : 5.6.0

Thanks for your help.

>All comments

Hey there, dot env does not work on a client builds.

See more info about why here
https://github.com/motdotla/dotenv/issues/172

There is also a common workaround to use
https://github.com/mrsteele/dotenv-webpack

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shellscape picture shellscape  Â·  3Comments

Quocnamit picture Quocnamit  Â·  3Comments

marcusradell picture marcusradell  Â·  3Comments

goldbergyoni picture goldbergyoni  Â·  3Comments

acharotariya picture acharotariya  Â·  3Comments