Closed
Description
Describe the bug
If dotenvOptions.path
is not set then dotenv
will proceed with its default path of
path.resolve(process.cwd(), '.env')
and since process.cwd()
is the VS Code installation directory, it will not find anything. Setting dotenvOptions.path
to a relative path also fails, for likely the same reason.
To Reproduce
Steps to reproduce the behavior:
- In some React project
Add a.env
file at the project root containingHELLO=WORLD
- In
typescript-plugin-css-modules
Add the following after thedotenv.config
call in index.ts and rebuild:logger.log(`process.env.HELLO after dotenv.config = ${process.env.HELLO}`);
- Put the above modified version of
typescript-plugin-css-modules
in the React project'snode_modules
- Add
typescript-plugin-css-modules
tocompilerOptions.plugins
in the React project'stsconfig.json
with no additional options - Reload Window in VS Code for the React project, then view a ts/tsx file and open the TS Server log
tsserver.log
contains:Loading from default location with[typescript-plugin-css-modules] process.env.HELLO after dotenv.config = undefined
dotenvOptions.path
unset = FAILURE- Add the following options for
typescript-plugin-css-modules
totsconfig.json
:"options": { "dotenvOptions": { "path": "./.env" } }
- Reload Window in VS Code, view the ts/tsx file again, and open the TS Server log
tsserver.log
contains:Loading from relative path in[typescript-plugin-css-modules] process.env.HELLO after dotenv.config = undefined
dotenvOptions.path
= FAILURE- Set the following options for
typescript-plugin-css-modules
intsconfig.json
:"options": { "dotenvOptions": { "path": "C:/Full/Absolute/Path/to/Project/.env" } }
- Reload Window in VS Code, view the ts/tsx file again, and open the TS Server log
tsserver.log
shows:Loading from absolute path in[typescript-plugin-css-modules] process.env.HELLO after dotenv.config = WORLD
dotenvOptions.path
= ONLY SUCCESS
Expected behavior
- Plugin can direct
dotenv
to load a.env
file located at the root of the project withoutdotenvOptions.path
having to be set - Plugin can direct
dotenv
to load a file from a relative path indotenvOptions.path