在YARN构建后,从.nuxt/dist/client文件夹中丢失一个.js资源
我正在尝试使用Apache和PM2部署我的NUXT项目。
NUXT项目将是前端,并且具有不同域上的后端API。 我的虚拟主机设置正常,我可以访问登录页面,但由于某些原因,它总是在一个.js文件上返回404,该文件应该在我运行yarn build build
内部。 DIST/客户端文件夹。
不过,值得注意的一些奇怪的事情是,当我使用无效的api_url时,例如我使用不存在的URL https://xxx.xxx/api/1
而不是正确的url https://xxx.xxx/api/v1
。重试纱构建
和PM2重新启动后,错误将消失。
我的设置:
- OS:Debian 11
- Server:Apache2& PM2
我的nuxt.config.js
import colors from "vuetify/es5/util/colors";
export default {
// Global page headers: https://go.nuxtjs.dev/config-head
head: {
titleTemplate: "%s - " + process.env.APP_NAME,
title: process.env.APP_NAME,
htmlAttrs: {
lang: "en",
},
meta: [
{ charset: "utf-8" },
{ name: "viewport", content: "width=device-width, initial-scale=1" },
{ hid: "description", name: "description", content: "" },
{ name: "format-detection", content: "telephone=no" },
],
link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }],
},
watchers: {
webpack: {
aggregateTimeout: 300,
poll: 1000,
},
},
auth: {
strategies: {
laravelPassport: {
provider: "laravel/passport",
endpoints: {
userInfo: process.env.API_URL + "/me",
},
url: process.env.API_SERVER,
clientId: process.env.PASSPORT_CLIENT_ID,
clientSecret: process.env.PASSPORT_CLIENT_SECRET,
},
local: {
endpoints: {
login: {
url: "/user/login",
method: "post",
propertyName: "data.access_token",
},
logout: { url: "/user/logout", method: "post" },
user: { url: "/me", method: "get", propertyName: "data" },
},
token: {
property: "data.access_token",
},
user: {
property: "data",
},
tokenRequired: true,
tokenType: "Bearer",
autoFetchUser: true,
},
customStrategy: {
scheme: "~/schemes/customScheme",
endpoints: {
login: {
url: "/user/login",
method: "post",
propertyName: "data.access_token",
},
logout: { url: "/user/logout", method: "post" },
user: { url: "/me", method: "get", propertyName: "data" },
},
tokenRequired: true,
tokenType: "Bearer",
autoFetchUser: true,
},
},
redirect: {
login: "/",
logout: "/",
home: "/admin",
},
},
router: {
middleware: ["auth"],
},
// Global CSS: https://go.nuxtjs.dev/config-css
css: [],
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: ["~plugins/vue-api-query"],
// Auto import components: https://go.nuxtjs.dev/config-components
components: true,
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [
// https://go.nuxtjs.dev/vuetify
"@nuxtjs/vuetify",
],
// Modules: https://go.nuxtjs.dev/config-modules
modules: ["@nuxtjs/axios", "@nuxtjs/auth-next"],
// Vuetify module configuration: https://go.nuxtjs.dev/config-vuetify
vuetify: {
customVariables: ["~/assets/variables.scss"],
theme: {
dark: false,
themes: {
dark: {
primary: colors.blue.darken2,
accent: colors.grey.darken3,
secondary: colors.amber.darken3,
info: colors.teal.lighten1,
warning: colors.amber.base,
error: colors.deepOrange.accent4,
success: colors.green.accent3,
},
},
},
},
// Build Configuration: https://go.nuxtjs.dev/config-build
build: {
maxChunkSize: 300000,
extend(config, ctx) {
config.performance.maxAssetSize = 700 * 1024;
},
},
// Axios module configuration: https://go.nuxtjs.dev/config-axios
axios: {
baseURL: process.env.API_SERVER || "https://xxx.xxx",
apiUrl: process.env.API_URL || "https://xxx.xxx/api/v1",
headers: {
common: {
Platform: "web",
},
},
},
};
I'm trying to deploy my Nuxt project using apache and pm2.
The nuxt project will be the front-end, and it has a backend api that is on a different domain.
I got the virtual host setup fine, I can access the login page but for some reasons, it always returns a 404 on one .js file that's supposed to be generated after I ran yarn build
inside .nuxt/dist/client folder.
Some odd thing that's worth noting though is that when I use an invalid API_URL, like if I use a non-existent url https://xxx.xxx/api/1
instead of the correct url https://xxx.xxx/api/v1
. The error will disappear after retrying yarn build
and pm2 restart
My setup:
- OS: Debian 11
- Server: Apache2 & pm2
My nuxt.config.js
import colors from "vuetify/es5/util/colors";
export default {
// Global page headers: https://go.nuxtjs.dev/config-head
head: {
titleTemplate: "%s - " + process.env.APP_NAME,
title: process.env.APP_NAME,
htmlAttrs: {
lang: "en",
},
meta: [
{ charset: "utf-8" },
{ name: "viewport", content: "width=device-width, initial-scale=1" },
{ hid: "description", name: "description", content: "" },
{ name: "format-detection", content: "telephone=no" },
],
link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }],
},
watchers: {
webpack: {
aggregateTimeout: 300,
poll: 1000,
},
},
auth: {
strategies: {
laravelPassport: {
provider: "laravel/passport",
endpoints: {
userInfo: process.env.API_URL + "/me",
},
url: process.env.API_SERVER,
clientId: process.env.PASSPORT_CLIENT_ID,
clientSecret: process.env.PASSPORT_CLIENT_SECRET,
},
local: {
endpoints: {
login: {
url: "/user/login",
method: "post",
propertyName: "data.access_token",
},
logout: { url: "/user/logout", method: "post" },
user: { url: "/me", method: "get", propertyName: "data" },
},
token: {
property: "data.access_token",
},
user: {
property: "data",
},
tokenRequired: true,
tokenType: "Bearer",
autoFetchUser: true,
},
customStrategy: {
scheme: "~/schemes/customScheme",
endpoints: {
login: {
url: "/user/login",
method: "post",
propertyName: "data.access_token",
},
logout: { url: "/user/logout", method: "post" },
user: { url: "/me", method: "get", propertyName: "data" },
},
tokenRequired: true,
tokenType: "Bearer",
autoFetchUser: true,
},
},
redirect: {
login: "/",
logout: "/",
home: "/admin",
},
},
router: {
middleware: ["auth"],
},
// Global CSS: https://go.nuxtjs.dev/config-css
css: [],
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: ["~plugins/vue-api-query"],
// Auto import components: https://go.nuxtjs.dev/config-components
components: true,
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [
// https://go.nuxtjs.dev/vuetify
"@nuxtjs/vuetify",
],
// Modules: https://go.nuxtjs.dev/config-modules
modules: ["@nuxtjs/axios", "@nuxtjs/auth-next"],
// Vuetify module configuration: https://go.nuxtjs.dev/config-vuetify
vuetify: {
customVariables: ["~/assets/variables.scss"],
theme: {
dark: false,
themes: {
dark: {
primary: colors.blue.darken2,
accent: colors.grey.darken3,
secondary: colors.amber.darken3,
info: colors.teal.lighten1,
warning: colors.amber.base,
error: colors.deepOrange.accent4,
success: colors.green.accent3,
},
},
},
},
// Build Configuration: https://go.nuxtjs.dev/config-build
build: {
maxChunkSize: 300000,
extend(config, ctx) {
config.performance.maxAssetSize = 700 * 1024;
},
},
// Axios module configuration: https://go.nuxtjs.dev/config-axios
axios: {
baseURL: process.env.API_SERVER || "https://xxx.xxx",
apiUrl: process.env.API_URL || "https://xxx.xxx/api/v1",
headers: {
common: {
Platform: "web",
},
},
},
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在寻找几天的答案后,我找不到解决问题的解决方案。
只是发现这是一个PM2问题,以某种方式停止纱线来生成一些文件。事实证明,当我停止PM2进程时,它仍在背景上运行。
以下是您可以检查是否遇到相同问题的方法:
pm2 stop -name
或pm2停止PM2
PM2删除-name
或PM2删除所有
(如果您没有其他进程运行)pm2 ls
确认没有,则没有其他运行PM2 LS
登录。如果仍有进程正在运行,请停止它们。纱构建
和PM2开始
After searching for answers for days, I couldn't find the solution to my problem.
Only to find out that it's a pm2 issue somehow stopping yarn to generate some files. It turns out that when I stopped pm2 processes, it was still running on the background.
Here's how you can check if you have the same problem:
pm2 stop --name
orpm2 stop all
(if you have no other processes running)pm2 delete --name
orpm2 delete all
(if you have no other processes running)pm2 ls
to confirm that there is no other process runningpm2 ls
. If there are still processes running, stop them.yarn build
andpm2 start