Dotenv: can't resolve 'fs' in angular

Created on 7 Feb 2019  路  3Comments  路  Source: motdotla/dotenv

environments:

Angular CLI: 7.2.3
Node: 11.6.0
OS: darwin x64
Angular: 7.2.2

Error behaviour

ERROR in ./node_modules/dotenv/lib/main.js
Module not found: Error: Can't resolve 'fs' in '/node_modules/dotenv/lib'

steps

import * as dotenv from "dotenv";

dotenv.config();
export const environment = {
  production: false,
  'baseurl': process.env.BASEURL
};

tsconfg.json

{ "compileOnSave": false, "compilerOptions": { "allowSyntheticDefaultImports": true, "baseUrl": "src", "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false, "module": "es2015", "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, "importHelpers": true, "target": "es6", "paths": { "@app/*": ["app/*"] }, "types": [ // add node as an option "node" ], "typeRoots": [ "node_modules/@types" ], "lib": [ "es2018", "dom", "es5", "es6" ] } }

i'm working with angular and use library for .env file.it's work good for node but when i'm used with typescript it gives me error.how to solve ?

Most helpful comment

Why is it closed? Nothing was solved here.

All 3 comments

You should only use dotenv in Node.js projects or at build time for browser-based projects like with Angular. Removing dotenv from your client-side code will resolve this error.

any solution to fix it?

Why is it closed? Nothing was solved here.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ycmjason picture ycmjason  路  4Comments

shellscape picture shellscape  路  3Comments

danawoodman picture danawoodman  路  3Comments

datasmurfen picture datasmurfen  路  5Comments

Vandivier picture Vandivier  路  3Comments