开发者社区 > 云原生 > Serverless > 正文

函数计算的nextjs 部署失败,node20,怎么解决?

函数计算的nextjs 部署失败,node20,怎么解决?f41cda686efc22425facc12a6eef7861.png
edition: 3.0.0
name: web-framework-app
access: 'undefined'
vars:
region: 'cn-shanghai'
functionName: 'ship'
resources:
framework:
component: fc3
actions:
pre-deploy:

    - run: export PATH=/usr/local/versions/node/v20.11.0/bin:$PATH && npm install --production --registry=https://registry.npmmirror.com
      path: ./
    - run: export PATH=/usr/local/versions/node/v20.11.0/bin:$PATH && npm run build
      path: ./
    - run: cp -r public .next/standalone/public
      path: ./
    - run: mv static standalone/.next/static
      path: .next
props:
  region: ${vars.region}
  description: Serverless Devs Web Framework Function
  runtime: custom.debian10
  timeout: 60
  layers:
    - acs:fc:${vars.region}:official:layers/Nodejs20/versions/1
  environmentVariables:
    PATH: >-
      /opt/nodejs20/bin:/usr/local/bin/apache-maven/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/ruby/bin
  customRuntimeConfig:
    command:
      - node
      - server.js
    port: 3000
  functionName: ${vars.functionName}
  code: .next/standalone
  triggers:
    - triggerName: httpTrigger
      triggerType: http
      triggerConfig:
        authType: anonymous
        methods:
          - GET

fc3_domain_0:
component: fc3-domain
props:
region: ${vars.region}
domainName: auto
protocol: HTTP
routeConfig:
routes:

      - path: /*
        functionName: ${vars.functionName}

配置如上,不确定哪里配置有问题

展开
收起
三分钟热度的鱼 2024-04-17 20:03:27 17 0
1 条回答
写回答
取消 提交回答
  • 参考

    ------------------------------------

    If you need English case, you can refer to [s_en.yaml] file

    ------------------------------------

    欢迎您使用阿里云函数计算 FC 组件进行项目开发

    组件仓库地址:https://github.com/devsapp/fc

    组件帮助文档:https://www.serverless-devs.com/fc/readme

    Yaml参考文档:https://www.serverless-devs.com/fc/yaml/readme

    关于:

    - Serverless Devs和FC组件的关系、如何声明/部署多个函数、超过50M的代码包如何部署

    - 关于.fcignore使用方法、工具中.s目录是做什么、函数进行build操作之后如何处理build的产物

    等问题,可以参考文档:https://www.serverless-devs.com/fc/tips

    关于如何做CICD等问题,可以参考:https://www.serverless-devs.com/serverless-devs/cicd

    关于如何进行环境划分等问题,可以参考:https://www.serverless-devs.com/serverless-devs/extend

    更多函数计算案例,可参考:https://github.com/devsapp/awesome/

    有问题快来钉钉群问一下吧:33947367

    ------------------------------------

    edition: 1.0.0
    name: web-framework-app

    access 是当前应用所需要的密钥信息配置:

    密钥配置可以参考:https://www.serverless-devs.com/serverless-devs/command/config

    密钥使用顺序可以参考:https://www.serverless-devs.com/serverless-devs/tool#密钥使用顺序与规范

    access: "undefined"

    vars: # 全局变量
    region: "cn-hangzhou"
    functionName: "next"
    service:
    name: "web-framework"
    description: 'Serverless Devs Web Framework Service'
    services:
    framework: # 业务名称/模块名称

    # 如果只想针对 framework 下面的业务进行相关操作,可以在命令行中加上 framework,例如:
    # 只对framework进行构建:s framework build
    # 如果不带有 framework ,而是直接执行 s build,工具则会对当前Yaml下,所有和 framework 平级的业务模块(如有其他平级的模块,例如下面注释的next-function),按照一定顺序进行 build 操作
    component: fc # 组件名称,Serverless Devs 工具本身类似于一种游戏机,不具备具体的业务能力,组件类似于游戏卡,用户通过向游戏机中插入不同的游戏卡实现不同的功能,即通过使用不同的组件实现不同的具体业务能力
    actions:       # 自定义执行逻辑,关于actions 的使用,可以参考:https://www.serverless-devs.com/serverless-devs/yaml#行为描述
      pre-deploy: # 在deploy之前运行
        - run: ls /usr/local/versions/node              # 要执行的系统命令,类似于一种钩子的形式
          path: ./code   
        - run: export PATH=/usr/local/versions/node/v20.8.1/bin:$PATH && npm install --production --registry=https://registry.npmmirror.com                   # 要执行的系统命令,类似于一种钩子的形式
          path: ./code                                    # 执行系统命令/钩子的路径
        - run: export PATH=/usr/local/versions/node/v20.8.1/bin:$PATH && npm run build
          path: ./code
        - run: cp -r public .next/standalone/public
          path: ./code
        - run: mv static standalone/.next/static
          path: ./code/.next
    

    - component: fc build --use-docker # 要运行的组件,格式为【component: 组件名 命令 参数】(可以通过s cli registry search --type Component 获取组件列表)

    - plugin: myplugin # 与运行的插件 (可以通过s cli registry search --type Plugin 获取组件列表)

    args: # 插件的参数信息

    testKey: testValue

    post-deploy: # 在deploy之后运行

    - component: fc versions publish # 要运行的命令行

    props: # 组件的属性值
      region: ${vars.region}         # 关于变量的使用方法,可以参考:https://www.serverless-devs.com/serverless-devs/yaml#变量赋值
      service: ${vars.service}
      function:
        name: ${vars.functionName}
        description: 'Serverless Devs Web Framework Function'
        codeUri: './code/.next/standalone'
        runtime: custom.debian10
        timeout: 60
        caPort: 3000
        layers:
          - acs:fc:${vars.region}:official:layers/Nodejs20/versions/1
        environmentVariables:
          PATH: /opt/nodejs20/bin:/usr/local/bin/apache-maven/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/ruby/bin
        customRuntimeConfig:
          command:
            - node
            - server.js
      triggers:
        - name: httpTrigger
          type: http
          config:
            authType: anonymous
            methods:
              - GET
      customDomains:
        - domainName: auto
          protocol: HTTP
          routeConfigs:
            - path: '/*'
    

    next-function: # 第二个函数的案例,仅供参考

    # 如果在当前项目下执行 s deploy,会同时部署模块:

    # helloworld:服务hello-world-service,函数cpp-event-function

    # next-function:服务hello-world-service,函数next-function-example

    # 如果想单独部署当前服务与函数,可以执行 s + 模块名/业务名 + deploy,例如:s next-function deploy

    # 如果想单独部署当前函数,可以执行 s + 模块名/业务名 + deploy function,例如:s next-function deploy function

    # 更多命令可参考:https://www.serverless-devs.com/fc/readme#文档相关

    component: fc

    props:

    region: ${vars.region}

    service: ${vars.service} # 应用整体的服务配置

    function: # 定义一个新的函数

    name: next-function-example

    description: 'hello world by serverless devs' 此回答整理自钉群“阿里函数计算官网客户”

    2024-04-17 20:53:37
    赞同 2 展开评论 打赏

快速交付实现商业价值。

相关产品

  • 函数计算
  • 相关电子书

    更多
    探究 Node.js 的服务端之路 立即下载
    个推微服务实践 基于OpenResty 和Node.js 立即下载
    沪江基于Node.js大规模应用实践 立即下载