Nuxt 2.15.x部署到Azure提示找不到@nuxt/ufo模块问题求助
Nuxt 2.15.x部署到Azure提示找不到@nuxt/ufo依赖问题
我正在将Nuxt应用部署到Azure,近期已升级到最新版Nuxt,项目在本地运行正常,但部署到Azure时收到如下报错:
我了解到@nuxt/ufo模块在Nuxt 2.15.x版本中已被移除,我已执行rm -r -d *清空Azure应用wwwroot文件夹下的所有文件,再通过Visual Studio Code执行全新部署。
部署日志如下:
Starting deployment... Creating zip package... Zip package size: 53.6 MB Fetching changes. Cleaning up temp folders from previous zip deployments and extract -ce0578fcc258.zip (51.17 MB) to /tmp/zipdeploy/extracted Updating submodules. Preparing deployment for commit id 'd3a896856e'. Generating deployment script. Using cached version of deployment script (command: 'azure -y --no te/deployments/tools" --basic --sitePath "/tmp/zipdeploy/extracted Running deployment command... Command: "/home/site/deployments/tools/deploy.sh" Handling Basic Web Site deployment. Kudu sync from: '/tmp/zipdeploy/extracted' to: '/home/site/wwwroot Copying file: 'App.vue' Copying file: 'ecosystem.config.js' Copying file: 'main.js' Copying file: 'nuxt.config.js' Copying file: 'package-lock.json' Copying file: 'package.json' Copying file: 'sources.info' Copying file: 'test.env' Ignoring: .deployment Copying file: '.nuxt/App.js' Copying file: '.nuxt/auth.js' Copying file: '.nuxt/axios.js' Copying file: '.nuxt/client.js' Copying file: '.nuxt/cookie-universal-nuxt.js' Copying file: '.nuxt/empty.js' Copying file: '.nuxt/index.js' Copying file: '.nuxt/jsonp.js' Copying file: '.nuxt/loading.html' Copying file: '.nuxt/middleware.js' Copying file: '.nuxt/router.js' Copying file: '.nuxt/router.scrollBehavior.js' Copying file: '.nuxt/routes.json' Copying file: '.nuxt/server.js' Copying file: '.nuxt/store.js' Copying file: '.nuxt/utils.js' Copying file: '.nuxt/components/index.js' Copying file: '.nuxt/components/nuxt-build-indicator.vue' Copying file: '.nuxt/components/nuxt-child.js' Copying file: '.nuxt/components/nuxt-error.vue' Copying file: '.nuxt/components/nuxt-link.client.js' Copying file: '.nuxt/components/nuxt-link.server.js' Copying file: '.nuxt/components/nuxt-loading.vue' Copying file: '.nuxt/components/nuxt.js' Copying file: '.nuxt/components/plugin.js' Copying file: '.nuxt/components/readme.md' Copying file: '.nuxt/mixins/fetch.client.js' Copying file: '.nuxt/mixins/fetch.server.js' Copying file: '.nuxt/vetur/tags.json' Copying file: '.nuxt/views/app.template.html' Copying file: '.nuxt/views/error.html' Copying file: '.nuxt/vuetify/options.js' Copying file: '.nuxt/vuetify/plugin.js' Copying file: 'assets/README.md' Copying file: 'assets/logo.png' Copying file: 'assets/variables.scss' Copying file: 'assets/images/accessibility.jpg' Copying file: 'assets/images/collaboration.jpg' Omitting next output lines... Processed 1160 files... Processed 2537 files... Processed 3971 files... Processed 4957 files... Processed 6169 files... Processed 7610 files... Processed 9345 files... Processed 10695 files... Processed 12066 files... Processed 13778 files... Processed 15096 files... Processed 16553 files... Processed 18211 files... Processed 19594 files... Processed 20928 files... Processed 22606 files... Processed 24410 files... Processed 25672 files... Processed 26666 files... Processed 27857 files... Processed 29085 files... Finished successfully. Running post deployment command(s)... Triggering recycle (preview mode disabled). Deployment successful. completed.
我不清楚既然该模块已被移除,为什么部署后仍提示需要该依赖,本地可正常运行的项目中也不存在@nuxt/ufo文件夹。
package.json配置如下:
"scripts": { "dev": "nuxt", "build": "nuxt build", "start": "nuxt start", "generate": "nuxt generate", "lint:js": "eslint --ext .js,.vue --ignore-path .gitignore . --fix", "lint": "npm run lint:js" }, "dependencies": { "@microsoft/signalr": "^5.0.5", "@nuxtjs/auth-next": "^5.0.0-1610642462.1bcdc1e", "@nuxtjs/axios": "^5.12.2", "@nuxtjs/vuetify": "^1.11.2", "cookie-universal-nuxt": "^2.1.4", "core-js": "^3.6.5", "moment": "^2.29.1", "nuxt": "^2.15.8", "qrcode.vue": "^1.7.0", "vue-auth-image": "0.0.3", "vue-draggable-resizable": "^2.3.0", "vue-wordcloud": "^1.1.1" }, "devDependencies": { "@nuxtjs/eslint-module": "^3.0.2", "eslint": "^8.3.0", "eslint-plugin-nuxt": "^3.0.0", "eslint-plugin-vue": "^8.1.1", "sass-loader": "^10.1.1", "webpack": "^4.46.0" }
请问还有什么排查方向或者可尝试的解决方案?
更新1
我已将这个已废弃的包添加到package.json文件中重新部署,这也暴露出了底层问题:站点实际运行的仍是旧版本内容,但在KUDO中可以看到新代码已经部署成功。我停止Azure中的站点后,站点确实无法访问,可以确认我操作的是正确的应用实例。这也能解释@nuxt/ufo相关报错的原因:站点运行的仍是依赖该废弃模块的Nuxt 1.14.6版本旧代码。
解决方案
- 清理全量缓存:进入Kudu控制台的Debug控制台,先删除
/home/site/wwwroot下所有文件,再删除/home/site/deployments下所有历史部署记录,重启应用服务后重新执行全量部署,不要使用增量部署。 - 调整启动配置:进入Azure门户对应应用服务的「配置」-「常规设置」,确认启动命令设置为
npm run start,避免硬编码的旧版本启动路径被调用。 - 启用包直接运行模式:在应用服务的「配置」-「应用程序设置」中添加环境变量
WEBSITE_RUN_FROM_PACKAGE,值设为1,该配置会让Azure直接从你上传的部署包运行代码,完全绕过本地文件缓存,避免旧代码被加载,配置后重启服务生效。 - 确认构建产物正确性:本地解压你上传的部署zip包,随机打开
.nuxt目录下的js文件搜索是否存在@nuxt/ufo引用,确认本地构建的产物是正确的新版本,避免将旧的构建包上传部署。 - 重新安装依赖:如果你的依赖是在Azure端自动安装的,删除
/home/site/wwwroot/node_modules目录后手动执行npm install重新安装依赖,再启动服务。
内容的提问来源于stack exchange,提问作者Simon
相关产品推荐
相关产品推荐

