gpt4 book ai didi

android - 无法正确配置 expo 应用程序 `Failed to read config at:/app.config.js`

转载 作者:行者123 更新时间:2023-12-04 14:11:11 26 4
gpt4 key购买 nike

我正在尝试开发一个应用程序,但在添加 dotenv 后无法构建它。
在我的 app.config.js我有

import "dotenv/config";
const API_URL = process.env["API_URL"] || "";
const API_VERSION = process.env["API_VERSION"] || "";
const MIRAGE_ENABLED = process.env["MIRAGE_ENABLED"] === "true" ? true : false;
const NODE_ENV = process.env["NODE_ENV"];

export default {
name: "My Application",
version: "0.0.0",
extra: {
API_URL,
API_VERSION,
MIRAGE_ENABLED,
NODE_ENV,
},
};
在我的 app.json我有:
{
"expo": {
"name": "my-application",
"slug": "my-application",
"owner": "my-expo",
"privacy": "unlisted",
"version": "0.0.0",
"orientation": "landscape",
"icon": "./assets/images/icon.png",
"sdkVersion": "37.0.0",
"platforms": ["ios"],
"splash": {
"image": "./assets/images/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": ["**/*"],
"ios": {
"supportsTablet": true,
"bundleIdentifier": "io.company.my-application",
"buildNumber": "0.0.0"
}
}
}
看完 documentation我比以前更困惑了。 expo build 的输出是:
Failed to read config at: .../app.config.js
ConfigError: Failed to read config at: .../app.config.js
at Object.getDynamicConfig (/Users/me/.npm-global/lib/node_modules/expo-cli/node_modules/@expo/config/src/getConfig.ts:37:9)
at getConfig (/Users/me/.npm-global/lib/node_modules/expo-cli/node_modules/@expo/config/src/Config.ts:121:62)
at validateAsync (/@expo/xdl@58.0.12/src/project/Doctor.ts:438:24)
at Object.validateWithoutNetworkAsync (/@expo/xdl@58.0.12/src/project/Doctor.ts:419:10)
at /Users/me/.npm-global/lib/node_modules/expo-cli/src/exp.ts:644:35
at Command.<anonymous> (/Users/me/.npm-global/lib/node_modules/expo-cli/src/exp.ts:331:7
这根本没有帮助。搜索 Failed to read config at: .../app.config.js没有产生任何结果。
我究竟做错了什么?以这种方式使用 expo 进行配置的最佳实践是什么?任何帮助将不胜感激。

最佳答案

首先,您需要使用 app.config.js 中的环境变量覆盖 app.json。要覆盖 js 对象,您可以使用分隔符运算符,并提供“额外”变量,您可以使用额外键。让我举个例子:

import 'dotenv/config'

export default ({config}) => {
const appConfig = ({
...config,
version: process.env.VERSION,
//override anything you want
extra: {
API_URL: process.env.API_URL,
//...
}
});
return appConfig;
}
这会将流程环境变量附加到您的 list 中。如果您对 app.config.js 有任何读取错误,则可能是您没有安装 dotenv 包。让我知道。

关于android - 无法正确配置 expo 应用程序 `Failed to read config at:/app.config.js`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64219044/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com