[英]Why is Next.js's compile indicator showing up in my production build?
I noticed after building and deploying a Next.js website that the black compile indicator still shows up in the bottom-right of my browser like it would locally.在构建和部署 Next.js 网站后,我注意到黑色编译指示器仍然显示在浏览器的右下角,就像在本地一样。
This indicator: https://i.stack.imgur.com/FVWEU.gif本指标: https://i.stack.imgur.com/FVWEU.gif
On Next.js's website:在 Next.js 的网站上:
This indicator is only present in development mode and will not appear when building and running the app in production mode.该指标仅在开发模式下出现,在生产模式下构建和运行应用程序时不会出现。
Even locally when I run yarn build
and yarn start
, the indicator displays while the page loads.即使在本地运行yarn build
和yarn start
,指示器也会在页面加载时显示。
During the build process, it says:在构建过程中,它说:
Creating an optimized production build Done in 20.89s.创建优化的生产构建在 20.89 秒内完成。
My concern isn't so much that the indicator is displaying, because I can disable it.我关心的不是指示器正在显示,因为我可以禁用它。 I'm concerned that I'm not getting an optimized build since something is displaying that should only be displaying in development mode.我担心我没有得到优化的构建,因为正在显示的东西应该只在开发模式下显示。
Note: I can't share a link to the website as it is work-related.注意:我无法分享该网站的链接,因为它与工作相关。
Has anybody seen this issue before?有人见过这个问题吗?
Thanks in advance!提前致谢!
Technical information:技术信息:
Next.js Version 12.1.1 Next.js 版本 12.1.1
Dockerfile: Dockerfile:
FROM node:16.13.0-alpine
# Install packages.
WORKDIR /app
COPY package.json .
COPY yarn.lock .
RUN yarn install
# Copy all other files.
COPY . .
# Build the app.
RUN yarn build
# USER node
EXPOSE 3003
CMD ["yarn", "start"]
package.json (scripts block): package.json(脚本块):
"scripts": {
"dev": "node ssr-server.js",
"build": "next build",
"test": "node_modules/.bin/jest",
"test:coverage": "node_modules/.bin/jest --coverage",
"test:watch": "node_modules/.bin/jest --watch",
"start": "node ssr-server.js"
},
In the custom server JavaScript file, there should be a line that check if the environment is development or production:在自定义服务器 JavaScript 文件中,应该有一行检查环境是开发环境还是生产环境:
const dev = process.env.NODE_ENV !== 'production'
update the start
script in package.json
to set that environment variable:更新package.json
中的start
脚本以设置该环境变量:
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "NODE_ENV=production node ssr-server.js"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.