2016-08-21 48 views
0

我收到以下错误工作,当我尝试使用我的项目AVA使用dotenv安全.ENV不AVA

{ [Error: ENOENT: no such file or directory, open '.env'] errno: -2, code: 'ENOENT', syscall: 'open', path: '.env' } 
fs.js:549 
    return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode); 
       ^

Error: ENOENT: no such file or directory, open '.env.example' 

它看起来像AVA没有找到运行我的测试。 env或.env.example文件

是否有任何解决方法或解决方案?

这是一个回购协议,美可以很容易地重现该问题:https://github.com/sibelius/koa-env-ava

+0

你有一个回购或最小的再生产,你可以分享? – JaKXz

+0

是的,刚刚添加在问题上,也在这里:https://github.com/sibelius/koa-env-ava –

回答

1

刚刚看了一下,下面是把事情的工作一个PR:https://github.com/sibelius/koa-env-ava/pull/1

发生了什么事是dotenv-safe不知道在哪里找到您的.env.env.example文件,因此它会在src目录中查找并引发错误。我改写了你的src/config.js文件到你的项目的根目录自动查找:

const root = require('path').join.bind(this, __dirname, '..'); 

require('dotenv-safe').load({ 
    path: root('.env'), 
    sample: root('.env.example') 
}); 

export const API_URL = process.env.API_URL; 
export const SERVER_PORT = process.env.SERVER_PORT; 

这样dotenv-safe知道从哪里加载.env文件。