- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 792
Open
Description
When following the dotenv documentation, I cannot get dotenv to load my environment variables correctly.
What I've done:
- Created a brand new Feather.js app
- Installed dotenv as per the documentation
- Added a .envfile to both the root folder and thesrcfolder, these just has aMEMES=MEMES-WORKSvariable in it
- Made a test required configuration in configuration.jslike this:export const configurationSchema = Type.Intersect([ defaultAppConfiguration, Type.Object({ host: Type.String(), port: Type.Number(), public: Type.String(), memes: Type.String() // Made this required to test }) ]) 
- Updated my config/custom-environment-variables.jsonfile like this:{ "port": { "__name": "PORT", "__format": "number" }, "host": "HOSTNAME", "authentication": { "secret": "FEATHERS_SECRET" }, "memes": "MEMES" }
- Ran the following at the top of my app.jsandindex.jsfile:import * as dotenv from 'dotenv' dotenv.config(); 
When I start the API, I keep getting this error:
error: Unhandled Rejection ValidationError: validation failed
at validate10 (eval at compileSchema (directory\feathers-dotenv-issue\node_modules\ajv\dist\compile\index.js:89:30), <anonymous>:3:529)
at app.hooks.setup (directory\feathers-dotenv-issue\node_modules\@feathersjs\configuration\lib\index.js:25:31)
at Feathers.dispatch (directory\feathers-dotenv-issue\node_modules\@feathersjs\hooks\script\compose.js:30:43)
at Feathers.hookChain (directory\feathers-dotenv-issue\node_modules\@feathersjs\hooks\script\hooks.js:27:28)
at Feathers.dispatch (directory\feathers-dotenv-issue\node_modules\@feathersjs\hooks\script\compose.js:30:43)
at Feathers.<anonymous> (directory\feathers-dotenv-issue\node_modules\@feathersjs\hooks\script\compose.js:16:25)
at Feathers._setup (directory\feathers-dotenv-issue\node_modules\@feathersjs\hooks\script\hooks.js:44:53)
at Feathers.listen (directory\feathers-dotenv-issue\node_modules\@feathersjs\koa\lib\index.js:58:24)
at file:///C:/Data/Development/MTN/Playgrounds/feathers-dotenv-issue/src/index.js:13:5
at ModuleJob.run (node:internal/modules/esm/module_job:274:25) {
  errors: [
    {
      instancePath: '',
      schemaPath: '#/required',
      keyword: 'required',
      params: [Object],
      message: "must have required property 'memes'"
    }
  ],
  validation: true,
  ajv: true
}
I've also tried updating my config/default.json file like so:
{
  "host": "localhost",
  "port": 3030,
  "public": "./public/",
  "origins": [
    "http://localhost:3030"
  ],
  "paginate": {
    "default": 10,
    "max": 50
  },
  "memes": "MEMES_DOES_NOT_WORK"
}But then app.get('memes') keeps on returning "MEMES_DOES_NOT_WORK".
Changing from:
import * as dotenv from 'dotenv'
dotenv.config();to
import 'dotenv/config';does seem to work, but the problem is that I have a .env file that I need to read from a parent monorepo directory. So my actual file needs to look like this:
import * as dotenv from 'dotenv';
dotenv.config({ path: ['../../../.env.development.local', '../../../.env.development'] });Is there a way to specify the import path when using the import 'dotenv/config'; syntax?
Here is a repo that reproduces the issue: feathers-dotenv-issue.zip
Metadata
Metadata
Assignees
Labels
No labels