启动 Nuxt.js 应用程序时出错:找不到构建文件
Error starting Nuxt.js app: No build files found
$ npm run start
> app@1.2.3 start /home/app/ui/web
> nuxt start
FATAL No build files found in /home/app/ui/web/.nuxt/dist/server.
Use either `nuxt build` or `builder.build()` or start nuxt in development mode.
在多阶段构建的 Docker 映像中启动 Nuxt.js 应用程序时发生错误:
npm ci && npm run build
在构建阶段图像中
- 将构建的应用程序
.nuxt
以及 package.json
和 node_modules
复制到 运行-stage 图像中
关于环境的一些细节。
Nuxt.js应用模式为'spa'。丢失的文件确实存在于最终图像中,没有使用 volumes/mounts。 OS build-stage 和 运行-stage 图像的用户名不同,但是(希望如此)不应该是这种情况。
Nuxt.js 2.12.2,Node.js 14.16.0.
缺少 nuxt.config.js
。
在我将它复制到 运行-stage 图像中,并从 localhost
切换到 0.0.0.0
for server.host
属性 inside nuxt.config.js
,容器运行宁没问题:
> app@1.2.3 start /home/app/ui/web
> nuxt start
ℹ Listening on: http://172.17.0.2:3000/
因此,运行在服务器部署模式下构建产品所需的项目(表面上)如下:
/.nuxt
/node_modules
nuxt.config.js
package.json
关于最终工件中应包含的内容,文档在某种程度上含糊不清:
https://nuxtjs.org/docs/2.x/get-started/commands/#server-deployment
一个不同的 SO 问题启发了故障排除:
Nuxt deployment error: server resources are not available
更新
将 Nuxt 更新到 2.15.3,从临时 npm
构建切换到通过 yarn
.
的可重现构建
构建阶段变成了yarn install --frozen-lockfile && yarn build
。此外,将 node_modules
从构建阶段复制到 运行 阶段会将开发依赖项带入 prod,b/c Nuxt 应用程序的 prod 构建需要开发依赖项。因此,在 运行 阶段,切换到 yarn install --frozen-lockfile --production=true
而不是从之前的构建阶段复制 node_modules
。
从运行在服务器部署模式(https://nuxtjs.org/docs/2.x/features/deployment-targets/#server-hosting)中生产 Nuxt 应用程序的构建阶段复制的所需项目如下:
/.nuxt
nuxt.config.js
package.json
yarn.lock
$ npm run start
> app@1.2.3 start /home/app/ui/web
> nuxt start
FATAL No build files found in /home/app/ui/web/.nuxt/dist/server.
Use either `nuxt build` or `builder.build()` or start nuxt in development mode.
在多阶段构建的 Docker 映像中启动 Nuxt.js 应用程序时发生错误:
npm ci && npm run build
在构建阶段图像中- 将构建的应用程序
.nuxt
以及package.json
和node_modules
复制到 运行-stage 图像中
关于环境的一些细节。
Nuxt.js应用模式为'spa'。丢失的文件确实存在于最终图像中,没有使用 volumes/mounts。 OS build-stage 和 运行-stage 图像的用户名不同,但是(希望如此)不应该是这种情况。
Nuxt.js 2.12.2,Node.js 14.16.0.
缺少 nuxt.config.js
。
在我将它复制到 运行-stage 图像中,并从 localhost
切换到 0.0.0.0
for server.host
属性 inside nuxt.config.js
,容器运行宁没问题:
> app@1.2.3 start /home/app/ui/web
> nuxt start
ℹ Listening on: http://172.17.0.2:3000/
因此,运行在服务器部署模式下构建产品所需的项目(表面上)如下:
/.nuxt
/node_modules
nuxt.config.js
package.json
关于最终工件中应包含的内容,文档在某种程度上含糊不清: https://nuxtjs.org/docs/2.x/get-started/commands/#server-deployment
一个不同的 SO 问题启发了故障排除: Nuxt deployment error: server resources are not available
更新
将 Nuxt 更新到 2.15.3,从临时 npm
构建切换到通过 yarn
.
构建阶段变成了yarn install --frozen-lockfile && yarn build
。此外,将 node_modules
从构建阶段复制到 运行 阶段会将开发依赖项带入 prod,b/c Nuxt 应用程序的 prod 构建需要开发依赖项。因此,在 运行 阶段,切换到 yarn install --frozen-lockfile --production=true
而不是从之前的构建阶段复制 node_modules
。
从运行在服务器部署模式(https://nuxtjs.org/docs/2.x/features/deployment-targets/#server-hosting)中生产 Nuxt 应用程序的构建阶段复制的所需项目如下:
/.nuxt
nuxt.config.js
package.json
yarn.lock