{"action":"created","issue":{"url":"https://api.github.com/repos/motdotla/dotenv/issues/133","repository_url":"https://api.github.com/repos/motdotla/dotenv","labels_url":"https://api.github.com/repos/motdotla/dotenv/issues/133/labels{/name}","comments_url":"https://api.github.com/repos/motdotla/dotenv/issues/133/comments","events_url":"https://api.github.com/repos/motdotla/dotenv/issues/133/events","html_url":"https://github.com/motdotla/dotenv/issues/133","id":145471155,"node_id":"MDU6SXNzdWUxNDU0NzExNTU=","number":133,"title":"Using with ES6 modules","user":{"login":"jsonmaur","id":911274,"node_id":"MDQ6VXNlcjkxMTI3NA==","avatar_url":"https://avatars1.githubusercontent.com/u/911274?v=4","gravatar_id":"","url":"https://api.github.com/users/jsonmaur","html_url":"https://github.com/jsonmaur","followers_url":"https://api.github.com/users/jsonmaur/followers","following_url":"https://api.github.com/users/jsonmaur/following{/other_user}","gists_url":"https://api.github.com/users/jsonmaur/gists{/gist_id}","starred_url":"https://api.github.com/users/jsonmaur/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsonmaur/subscriptions","organizations_url":"https://api.github.com/users/jsonmaur/orgs","repos_url":"https://api.github.com/users/jsonmaur/repos","events_url":"https://api.github.com/users/jsonmaur/events{/privacy}","received_events_url":"https://api.github.com/users/jsonmaur/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":13,"created_at":"2016-04-03T08:43:44Z","updated_at":"2018-12-23T15:07:32Z","closed_at":"2016-04-15T04:38:25Z","author_association":"NONE","body":"In the case of using ES6 modules via `import`, configuring dotenv in the base file doesn't set the environment vars in sub-modules. For example:\n###### index.js\n\n``` javascript\nimport dotenv from 'dotenv'\ndotenv.config({ silent: true })\nimport hello from './hello'\n```\n###### hello.js\n\n``` javascript\nconsole.log(process.env) /* this doesn't have the environment vars in it */\n```\n\nThis is because babel compiles the above as\n\n``` javascript\nvar dotenv = require('dotenv')\nvar hello = require('./hello')\ndotenv.config({ silent: true })\n```\n\nIt works if I do `import 'dotenv/config'` instead, but then I can't specify the `silent` flag, so it throws an error if `.env` doesn't exist (for example, if running in production). I think a simple solution would be to allow something such as `import 'dotenv/register'` for a one-line, silent setup of the variables.\n"},"comment":{"url":"https://api.github.com/repos/motdotla/dotenv/issues/comments/449642484","html_url":"https://github.com/motdotla/dotenv/issues/133#issuecomment-449642484","issue_url":"https://api.github.com/repos/motdotla/dotenv/issues/133","id":449642484,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0OTY0MjQ4NA==","user":{"login":"dmark","id":7488653,"node_id":"MDQ6VXNlcjc0ODg2NTM=","avatar_url":"https://avatars2.githubusercontent.com/u/7488653?v=4","gravatar_id":"","url":"https://api.github.com/users/dmark","html_url":"https://github.com/dmark","followers_url":"https://api.github.com/users/dmark/followers","following_url":"https://api.github.com/users/dmark/following{/other_user}","gists_url":"https://api.github.com/users/dmark/gists{/gist_id}","starred_url":"https://api.github.com/users/dmark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmark/subscriptions","organizations_url":"https://api.github.com/users/dmark/orgs","repos_url":"https://api.github.com/users/dmark/repos","events_url":"https://api.github.com/users/dmark/events{/privacy}","received_events_url":"https://api.github.com/users/dmark/received_events","type":"User","site_admin":false},"created_at":"2018-12-23T15:07:32Z","updated_at":"2018-12-23T15:07:32Z","author_association":"NONE","body":"Trying to do this in a TypeScript environment:\r\n\r\n`env.ts`:\r\n\r\n```\r\nimport dotenv from 'dotenv'\r\ndotenv.config({ silent: true })\r\n```\r\nAfter installing `@types/dotenv`, I now get a 'has no default export.' error on `dotenv`. I am pretty new to JS and completely new to TS. The following is working for me but I have no idea whether this is an appropriate way to handle the import or not:\r\n\r\n`env.ts`:\r\n\r\n```\r\nimport * as dotenv from 'dotenv'\r\ndotenv.config()\r\n```"}}
{"actor":{"display_login":"dmark"}}