简体   繁体   English

如何将 Nuxt.js 部署到 Elastic Beanstalk?

[英]How to deploy Nuxt.js to Elastic Beanstalk?

I am very new to AWS and i have been following the tutorials out there but couldn't find the answer.我对 AWS 很陌生,我一直在关注那里的教程,但找不到答案。 So, what i did was i created simple nuxt application, no changes to the framework's script or anything.所以,我所做的是我创建了简单的 nuxt 应用程序,没有更改框架的脚本或任何东西。 I set my elastic beanstalk to run node.js settings.我将弹性豆茎设置为运行 node.js 设置。 and then i tried to deploy my /dist folder(using nuxt build) with the application's json folder as told by every tutorials.然后我尝试按照每个教程的说明,使用应用程序的 json 文件夹部署我的 /dist 文件夹(使用 nuxt 构建)。 but it gives me this this is what it looks on my webpage I think i have something wrong with which folders i deploy or do i have to actually deploy via the aws CLI, would that make a difference at all?但它给了我这就是它在我的网页上的外观我认为我部署的文件夹有问题,或者我必须通过 aws CLI 实际部署,这会有所不同吗?

eb log:电子日志:

-------------------------------------
/var/log/nodejs/nodejs.log
-------------------------------------
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /tmp/.npm/_logs/2019-09-29T16_00_28_939Z-debug.log

> portfolio@1.0.0 start /var/app/current
> cross-env NODE_ENV=production node server/index.js

internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module '/var/app/current/server/index.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)



The nodejs logs indicate to me that there is an issue with the build, an issue with how it's zipped, or an issue with your start command. nodejs 日志向我表明构建存在问题、压缩方式存在问题或启动命令存在问题。

The most common is incorrectly zipping source files最常见的是错误地压缩源文件

When you create a ZIP file in Mac OS X Finder or Windows Explorer, make sure you zip the files and subfolders themselves, rather than zipping the parent folder.当您在 Mac OS X Finder 或 Windows 资源管理器中创建 ZIP 文件时,请确保您使用 zip 文件和子文件夹本身,而不是压缩父文件夹。

In other words, do not right click the dist folder and click "zip", select all the files and folders (including hidden ones) and zip those.换句话说,不要右键单击 dist 文件夹并单击“zip”,select 所有文件和文件夹(包括隐藏的)和 zip 那些。 Elastic beanstalk, and many other AWS services, expect the zip to unpack into a flat structure, and not contain the parent folder when unzipped. Elastic beanstalk 和许多其他 AWS 服务期望 zip 解压缩成一个扁平结构,并且在解压缩时不包含父文件夹。

If this does not solve your problem, make sure you're zipping the correct folder.如果这不能解决您的问题,请确保您正在压缩正确的文件夹。 Try deleting your.nuxt and /dist folders, and running npm run build locally.尝试删除 your.nuxt 和 /dist 文件夹,然后在本地运行npm run build The folder that is produced (defaults to.nuxt) is the folder whose contents need to be zipped.生成的文件夹(默认为.nuxt)是需要压缩其内容的文件夹。

The reason it is throwing that error is because your launch command starts with cross-env .引发该错误的原因是您的启动命令以cross-env开头。 When it sees that it tries to run the globally installed package cross-env but it is not available globally, so it throws that error.当它看到它尝试运行全局安装的 package cross-env但它在全局不可用时,它会抛出该错误。 There are a few possible ways to address this:有几种可能的方法来解决这个问题:

  1. The easiest is to just change the start command to use a relative path to the locally installed version of cross-env , so your command should look something like this:最简单的方法是将 start 命令更改为使用本地安装的cross-env版本的相对路径,因此您的命令应如下所示:

    node_modules/cross-env/src/bin/cross-env.js node server/index.js

  2. You might also try adding npx to the front of your command, like so:您也可以尝试将npx添加到命令的前面,如下所示:

    npx cross-env NODE_ENV=production node server/index.js

    This should work but I have found that sometimes I get errors with specific packages, from what I can tell it is a bug with npx but I haven't had time to look into it.这应该可行,但我发现有时我会遇到特定软件包的错误,据我所知这是 npx 的一个错误,但我没有时间研究它。 Notably I did see this bug with a nuxt js app specifically so you might too, however I was using the nuxt cli which you are not.值得注意的是,我确实在一个 nuxt js 应用程序中看到了这个错误,所以你也可以,但是我使用的是你没有的 nuxt cli。

  3. The third option is you could look into installing the package globally using ebextensions.第三个选项是您可以考虑使用 ebextensions 全局安装 package。 In my work I haven't come across a situation where that has been necessary.在我的工作中,我没有遇到过需要这样做的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM