Skip to content

Commit 463251d

Browse files
committed
feat: allow to disable chunk building by setting DISABLE_CHUNK=1
1 parent 3adca26 commit 463251d

File tree

6 files changed

+496
-9
lines changed

6 files changed

+496
-9
lines changed

README_CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ BASE_URL=https://chatgpt1.nextweb.fun/api/proxy
121121

122122
1. 安装 nodejs 18 和 yarn,具体细节请询问 ChatGPT;
123123
2. 执行 `yarn install && yarn dev` 即可。⚠️ 注意:此命令仅用于本地开发,不要用于部署!
124-
3. 如果你想本地部署,请使用 `yarn install && yarn start` 命令,你可以配合 pm2 来守护进程,防止被杀死,详情询问 ChatGPT。
124+
3. 如果你想本地部署,请使用 `yarn install && yarn build && yarn start` 命令,你可以配合 pm2 来守护进程,防止被杀死,详情询问 ChatGPT。
125125

126126
## 部署
127127

docs/faq-cn.md

+17
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,23 @@ keepalive_timeout 300; # 设定keep-alive超时时间为65秒
105105

106106
API KEY 有问题。余额不足。
107107

108+
## 使用时遇到 "Error: Loading CSS chunk xxx failed..."
109+
110+
为了减少首屏白屏时间,默认启用了分块编译,技术原理见下:
111+
112+
- https://nextjs.org/docs/app/building-your-application/optimizing/lazy-loading
113+
- https://stackoverflow.com/questions/55993890/how-can-i-disable-chunkcode-splitting-with-webpack4
114+
- https://github.com/vercel/next.js/issues/38507
115+
- https://stackoverflow.com/questions/55993890/how-can-i-disable-chunkcode-splitting-with-webpack4
116+
117+
然而 NextJS 的兼容性比较差,在比较老的浏览器上会导致此报错,可以在编译时关闭分块编译。
118+
119+
对于 Vercel 平台,在环境变量中增加 `DISABLE_CHUNK=1`,然后重新部署即可;
120+
对于自行编译部署的项目,在构建时使用 `DISABLE_CHUNK=1 yarn build` 构建即可;
121+
对于 Docker 用户,由于 Docker 打包时已经构建完毕,所以暂不支持关闭此特性。
122+
123+
注意,关闭此特性后,用户会在第一次访问网站时加载所有资源,如果用户网络状况较差,可能会引起较长时间的白屏,从而影响用户使用体验,所以自行考虑。
124+
108125
# 网络服务相关问题
109126

110127
## Cloudflare 是什么?

docs/faq-en.md

+56-1
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,45 @@
11
# Frequently Asked Questions
22

33
## How to get help quickly?
4+
45
1. Ask ChatGPT / Bing / Baidu / Google, etc.
56
2. Ask online friends. Please provide background information and a detailed description of the problem. High-quality questions are more likely to get useful answers.
67

78
# Deployment Related Questions
89

910
## Why does the Docker deployment version always prompt for updates
11+
1012
The Docker version is equivalent to the stable version, and the latest Docker is always consistent with the latest release version. Currently, our release frequency is once every one to two days, so the Docker version will always be one to two days behind the latest commit, which is expected.
1113

1214
## How to deploy on Vercel
15+
1316
1. Register a Github account and fork this project.
1417
2. Register Vercel (mobile phone verification required, Chinese number can be used), and connect your Github account.
1518
3. Create a new project on Vercel, select the project you forked on Github, fill in the required environment variables, and start deploying. After deployment, you can access your project through the domain provided by Vercel. (Requires proxy in mainland China)
16-
* If you need to access it directly in China: At your DNS provider, add a CNAME record for the domain name, pointing to cname.vercel-dns.com. Then set up your domain access on Vercel.
19+
20+
- If you need to access it directly in China: At your DNS provider, add a CNAME record for the domain name, pointing to cname.vercel-dns.com. Then set up your domain access on Vercel.
1721

1822
## How to modify Vercel environment variables
23+
1924
- Enter the Vercel console page;
2025
- Select your chatgpt-next-web project;
2126
- Click on the Settings option at the top of the page;
2227
- Find the Environment Variables option in the sidebar;
2328
- Modify the corresponding values as needed.
2429

2530
## What is the environment variable CODE? Is it necessary to set it?
31+
2632
This is your custom access password, you can choose:
33+
2734
1. Do not set it, delete the environment variable. Be cautious: anyone can access your project at this time.
2835
2. When deploying the project, set the environment variable CODE (supports multiple passwords, separated by commas). After setting the access password, users need to enter the access password in the settings page to use it. See [related instructions](https://github.com/Yidadaa/ChatGPT-Next-Web#access-password)
2936

3037
## Why doesn't the version I deployed have streaming response
38+
3139
> Related discussion: [#386](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/386)
3240
3341
If you use nginx reverse proxy, you need to add the following code to the configuration file:
42+
3443
```
3544
# No caching, support streaming output
3645
proxy_cache off; # Turn off caching
@@ -44,89 +53,135 @@ keepalive_timeout 300; # Set keep-alive timeout to 65 seconds
4453
If you are deploying on netlify, this issue is still waiting to be resolved, please be patient.
4554

4655
## I've deployed, but it's not accessible
56+
4757
Please check and troubleshoot the following issues:
58+
4859
- Is the service started?
4960
- Is the port correctly mapped?
5061
- Is the firewall port open?
5162
- Is the route to the server okay?
5263
- Is the domain name resolved correctly?
5364

65+
## You may encounter an "Error: Loading CSS chunk xxx failed..."
66+
67+
To reduce the initial white screen time, Next.js enables chunking by default. You can find the technical details here:
68+
69+
- https://nextjs.org/docs/app/building-your-application/optimizing/lazy-loading
70+
- https://stackoverflow.com/questions/55993890/how-can-i-disable-chunkcode-splitting-with-webpack4
71+
- https://github.com/vercel/next.js/issues/38507
72+
- https://stackoverflow.com/questions/55993890/how-can-i-disable-chunkcode-splitting-with-webpack4
73+
74+
However, Next.js has limited compatibility with older browsers, which can result in this error.
75+
76+
You can disable chunking during building.
77+
78+
For Vercel platform, you can add `DISABLE_CHUNK=1` to the environment variables and redeploy.
79+
For self-deployed projects, you can use `DISABLE_CHUNK=1 yarn build` during the build process.
80+
For Docker users, as the build is already completed during packaging, disabling this feature is currently not supported.
81+
82+
Note that when you disable this feature, all resources will be loaded on the user's first visit. This may result in a longer white screen time if the user has a poor network connection, affecting the user experience. Please consider this when making a decision.
83+
5484
# Usage Related Questions
5585

5686
## Why does it always prompt "An error occurred, please try again later"
87+
5788
There could be many reasons, please check the following in order:
89+
5890
- First, check if your code version is the latest version, update to the latest version and try again;
5991
- Check if the api key is set correctly, the environment variable name must be uppercase with underscores;
6092
- Check if the api key is available;
6193
- If you still cannot determine the problem after going through the above steps, please submit a new issue in the issue area and attach the runtime log of vercel or the log of docker runtime.
6294

6395
## Why does ChatGPT's reply get garbled
96+
6497
In the settings page - model settings, there is an item called `temperature`. If this value is greater than 1, it may cause garbled replies. Adjust it back to within 1.
6598

6699
## It prompts "Now it's unauthorized, please enter the access password on the settings page" when using?
100+
67101
The project has set an access password through the environment variable CODE. When using it for the first time, you need to go to settings and enter the access code to use.
68102

69103
## It prompts "You exceeded your current quota, ..." when using?
104+
70105
The API KEY is problematic. Insufficient balance.
71106

72107
## What is a proxy and how to use it?
108+
73109
Due to IP restrictions of OpenAI, China and some other countries/regions cannot directly connect to OpenAI API and need to go through a proxy. You can use a proxy server (forward proxy) or a pre-configured OpenAI API reverse proxy.
110+
74111
- Forward proxy example: VPN ladder. In the case of docker deployment, set the environment variable HTTP_PROXY to your proxy address (http://address:port).
75112
- Reverse proxy example: You can use someone else's proxy address or set it up for free through Cloudflare. Set the project environment variable BASE_URL to your proxy address.
76113

77114
## Can I deploy it on a server in China?
115+
78116
It is possible but there are issues to be addressed:
117+
79118
- Proxy is required to connect to websites such as Github and OpenAI;
80119
- Domain name resolution requires filing for servers in China;
81120
- Chinese policy restricts proxy access to foreign websites/ChatGPT-related applications, which may be blocked.
82121

83122
# Network Service Related Questions
123+
84124
## What is Cloudflare?
125+
85126
Cloudflare (CF) is a network service provider offering CDN, domain management, static page hosting, edge computing function deployment, and more. Common use cases: purchase and/or host your domain (resolution, dynamic domain, etc.), apply CDN to your server (can hide IP to avoid being blocked), deploy websites (CF Pages). CF offers most services for free.
86127

87128
## What is Vercel?
129+
88130
Vercel is a global cloud platform designed to help developers build and deploy modern web applications more quickly. This project and many web applications can be deployed on Vercel with a single click for free. No need to understand code, Linux, have a server, pay, or set up an OpenAI API proxy. The downside is that you need to bind a domain name to access it without restrictions in China.
89131

90132
## How to obtain a domain name?
133+
91134
1. Register with a domain provider, such as Namesilo (supports Alipay) or Cloudflare for international providers, and Wanwang for domestic providers in China.
92135
2. Free domain name providers: eu.org (second-level domain), etc.
93136
3. Ask friends for a free second-level domain.
94137

95138
## How to obtain a server
139+
96140
- Examples of international server providers: Amazon Web Services, Google Cloud, Vultr, Bandwagon, Hostdare, etc.
97141
International server considerations: Server lines affect access speed in China; CN2 GIA and CN2 lines are recommended. If the server has difficulty accessing in China (serious packet loss, etc.), you can try using a CDN (from providers like Cloudflare).
98142
- Domestic server providers: Alibaba Cloud, Tencent, etc.
99143
Domestic server considerations: Domain name resolution requires filing; domestic server bandwidth is relatively expensive; accessing foreign websites (Github, OpenAI, etc.) requires a proxy.
100144

101145
# OpenAI-related Questions
146+
102147
## How to register an OpenAI account?
148+
103149
Go to chat.openai.com to register. You will need:
150+
104151
- A good VPN (OpenAI only allows native IP addresses of supported regions)
105152
- A supported email (e.g., Gmail or a company/school email, not Outlook or QQ email)
106153
- A way to receive SMS verification (e.g., SMS-activate website)
107154

108155
## How to activate OpenAI API? How to check API balance?
156+
109157
Official website (requires VPN): https://platform.openai.com/account/usage
110158
Some users have set up a proxy to check the balance without a VPN; ask online friends for access. Please verify the source is reliable to avoid API Key leakage.
111159

112160
## Why doesn't my new OpenAI account have an API balance?
161+
113162
(Updated April 6th) Newly registered accounts usually display API balance within 24 hours. New accounts are currently given a $5 balance.
114163

115164
## How to recharge OpenAI API?
165+
116166
OpenAI only accepts credit cards from designated regions (Chinese credit cards cannot be used). If the credit cards from your region is not supported, some options include:
167+
117168
1. Depay virtual credit card
118169
2. Apply for a foreign credit card
119170
3. Find someone online to top up
120171

121172
## How to access the GPT-4 API?
173+
122174
(Updated April 6th) Access to the GPT-4 API requires a separate application. Go to the following address and enter your information to join the waitlist (prepare your OpenAI organization ID): https://openai.com/waitlist/gpt-4-api
123175
Wait for email updates afterwards.
124176

125177
## How to use the Azure OpenAI interface
178+
126179
Please refer to: [#371](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/371)
127180

128181
## Why is my Token consumed so fast?
182+
129183
> Related discussion: [#518](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/518)
184+
130185
- If you have GPT-4 access and use GPT-4 API regularly, your bill will increase rapidly since GPT-4 pricing is about 15 times higher than GPT-3.5;
131186
- If you are using GPT-3.5 and not using it frequently, but still find your bill increasing fast, please troubleshoot immediately using these steps:
132187
- Check your API key consumption record on the OpenAI website; if your token is consumed every hour and each time consumes tens of thousands of tokens, your key must have been leaked. Please delete it and regenerate it immediately. **Do not check your balance on random websites.**

next.config.mjs

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
import webpack from "webpack";
2+
13
const mode = process.env.BUILD_MODE ?? "standalone";
24
console.log("[Next] build mode", mode);
35

6+
const disableChunk = !!process.env.DISABLE_CHUNK || mode === "export";
7+
console.log("[Next] build with chunk: ", !disableChunk);
8+
49
/** @type {import('next').NextConfig} */
510
const nextConfig = {
611
webpack(config) {
@@ -9,6 +14,12 @@ const nextConfig = {
914
use: ["@svgr/webpack"],
1015
});
1116

17+
if (disableChunk) {
18+
config.plugins.push(
19+
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
20+
);
21+
}
22+
1223
return config;
1324
},
1425
output: mode,

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
"husky": "^8.0.0",
5656
"lint-staged": "^13.2.2",
5757
"prettier": "^2.8.7",
58-
"typescript": "4.9.5"
58+
"typescript": "4.9.5",
59+
"webpack": "^5.88.1"
5960
},
6061
"resolutions": {
6162
"lint-staged/yaml": "^2.2.2"

0 commit comments

Comments
 (0)