GithubHelp home page GithubHelp logo

Comments (16)

tangly1024 avatar tangly1024 commented on May 30, 2024

这是个有趣的提议!

  • 据我所知,腾讯云是支持Serverless应用部署的,同时也有对NextJS的😂

image

image

  • 但遗憾的是腾讯云似乎对Next的兼容性并不太好,我的部署尝试并不成功。看来NextJS还是和Vercel比较默契。

image

image

from notionnext.

SenLief avatar SenLief commented on May 30, 2024

我也试了一下,并且查看了下issue貌似是因为包过大引起的,能否缩减一下包的体积呢?已经超过200m了。

from notionnext.

tangly1024 avatar tangly1024 commented on May 30, 2024

✅包过大可能影响编译

日志中确实有提到包的体积过大的可能性:

[2022-03-28 16:51:05] 当前项目文件大小超过200MB,部署有可能会失败。如果失败建议使用 Webpack, Parcel 或 Layer 来减小项目文件大小后重试

🤔真的是包过大导致的吗

但我想这不是导致编译失败的主要原因,更主要的原因是这里:编译过程载入next.config.js配置失败:

[2022-03-28 16:51:19] error - Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error
[2022-03-28 16:51:19]
[2022-03-28 16:51:19] > Build error occurred
[2022-03-28 16:51:19] Error: Not supported
[2022-03-28 16:51:19] at Object.loadConfig (/root/workspace/node_modules/next/dist/server/config.js:70:78)
[2022-03-28 16:51:19] npm ERR! code ELIFECYCLE
[2022-03-28 16:51:19] npm ERR! errno 1
[2022-03-28 16:51:19] npm ERR! [email protected] build: next build && next-sitemap --config next-sitemap.config.js
[2022-03-28 16:51:19] npm ERR! Exit status 1

😁引起失败的根本原因

导致失败的原因是显而易见的:版本不兼容
腾讯云采用的NodeJS版本10.21.0,无法编译nextjs12.1.1的项目。至少需要12.22.0的版本,而我在开发环境的node版本就已经是 v16.13.0

[2022-03-28 16:50:45] npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">=12.22.0"} (current: {"node":"10.21.0","npm":"6.14.4"})
[2022-03-28 16:50:45] npm WARN notsup Not compatible with your version of node/npm: [email protected]
[2022-03-28 16:50:45] npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">=12"} (current: {"node":"10.21.0","npm":"6.14.4"})
[2022-03-28 16:50:45] npm WARN notsup Not compatible with your version of node/npm: [email protected]
[2022-03-28 16:50:45] npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">=12"} (current: {"node":"10.21.0","npm":"6.14.4"})
[2022-03-28 16:50:45] npm WARN notsup Not compatible with your version of node/npm: [email protected]
[2022-03-28 16:50:45] npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">=12"} (current: {"node":"10.21.0","npm":"6.14.4"})
[2022-03-28 16:50:45] npm WARN notsup Not compatible with your version of node/npm: [email protected]
[2022-03-28 16:50:45] npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">= 12.0.0"} (current: {"node":"10.21.0","npm":"6.14.4"})
[2022-03-28 16:50:45] npm WARN notsup Not compatible with your version of node/npm: [email protected]

解决方法

只能是期待腾讯云更新一下版本吧 。而NextJS本就是Vercel官方推出的框架,故不存在此类兼容性问题。

from notionnext.

SenLief avatar SenLief commented on May 30, 2024

看了下文档,nodejs的版本最高时支持到16.13的,但是不知道默认的版本为什么不能强制,如果选择api网关触发的是可以部署到16.13,不过我试了一下也没有成功。

开始怀疑时nextjs被限制了10.15,但是我新部署demo的可以部署到16.13,不知道什么情况。

另外这个触发方式在vercel属于哪一种触发部署?nextjs会定时拉取api?还是notion api会推送过来然后部署?

from notionnext.

SenLief avatar SenLief commented on May 30, 2024

采用这个serverless.yml部署是可以部署的,不过访问不到。

component: http
name: nextDemo
inputs:
  src:
    dist: ./
    hook: npm run build
    exclude:
      - .env
  faas:
    runtime: Nodejs16.13
    framework: nextjs
    name: ${name}
  apigw:
    protocols:
      - http
      - https
app: notion

from notionnext.

tangly1024 avatar tangly1024 commented on May 30, 2024

开始怀疑时nextjs被限制了10.15,但是我新部署demo的可以部署到16.13,不知道什么情况。

按照官方文档的说明似乎默认是10.15的node版本 ,要在环境变量中配置node版本。
而且只要在环境变量中增加一堆key/value配置即可

另外这个触发方式在vercel属于哪一种触发部署?nextjs会定时拉取api?还是notion api会推送过来然后部署?

Vercel是自动触发的:利用github的hook特性。当代码有更新时会自动通知vercel平台。
而文章的动态更新则是利用NextJS本身增量式的网站渲染:ISR特性

from notionnext.

SenLief avatar SenLief commented on May 30, 2024

我在后面换了其他版本的node测试仍然不行,原因应该是没有写入的权限,这个是平台的问题,腾讯的ssr只有对/tmp的写入权限,但是nextjs要向.next文件夹写入一个BUID,造成无法部署,所以说的对还是vercel吧。

之所以想换腾讯的,主要还是国内的访问速度上,部署的时候有海外加速,所以还蛮合适的。😄

from notionnext.

tangly1024 avatar tangly1024 commented on May 30, 2024

优化国内的访问速度确实很重要,这个问题我持续关注一下,找找其他解决方案。

from notionnext.

SenLief avatar SenLief commented on May 30, 2024

嗯,我用上面得手动部署了一下,是可以部署,只不过还是报错,应该是文件写入的问题。

from notionnext.

SenLief avatar SenLief commented on May 30, 2024

部署调用失败的日志

日志:

START RequestId: 0a6fc635c0d72ed3e19ce67ce8483094

ready - started server on 0.0.0.0:9000, url: http://localhost:9000

Init Report RequestId: 0a6fc635c0d72ed3e19ce67ce8483094 Coldstart: 128ms (PullCode: 0ms InitRuntime: 1ms InitFunction: 127ms) Memory: 512MB MemUsage: 17.36MB

ready - started server on 0.0.0.0:3000, url: http://localhost:3000

[Error: EROFS: read-only file system, unlink '/var/user/.next/BUILD_ID'] {

  errno: -30,

  code: 'EROFS',

  syscall: 'unlink',

  path: '/var/user/.next/BUILD_ID'

}

ERROR RequestId: 0a6fc635c0d72ed3e19ce67ce8483094 Result: {"errorCode":-1,"errorMessage":"Process exited unexpectedly.","statusCode":439}

END RequestId: 0a6fc635c0d72ed3e19ce67ce8483094

Report RequestId: 0a6fc635c0d72ed3e19ce67ce8483094 Duration: 1469ms Memory: 512MB MemUsage: 117.74MB

from notionnext.

tangly1024 avatar tangly1024 commented on May 30, 2024

我在后面换了其他版本的node测试仍然不行,原因应该是没有写入的权限,这个是平台的问题,腾讯的ssr只有对/tmp的写入权限,但是nextjs要向.next文件夹写入一个BUID,造成无法部署,所以说的对还是vercel吧。

确实如此,腾讯云函数环境不支持除开/tmp目录以外的文件读写。

from notionnext.

SenLief avatar SenLief commented on May 30, 2024

嗯,比较奇怪的是我用官方的demo部署是可以部署的,但是部署这个就不行了,日志也不详细,所以说没办法。

from notionnext.

tangly1024 avatar tangly1024 commented on May 30, 2024

修改启动脚本代码迁入/tmp目录,可以避开目录无法写入的问题:

[Error: EROFS: read-only file system, unlink '/var/user/.next/BUILD_ID'] {

相关脚本

scf_bootstrap

#!/bin/bash
pIDa=`/usr/sbin/lsof -i :9000|grep -v "PID" | awk '{print $2}'`
if [ "$pIDa" != "" ];
then
   echo "1"
else
  cp -r . /tmp
  cd /tmp
  export PORT=9000
  /var/lang/node16/bin/node start.js
  #node ./start.js
fi

start.js

#!/var/lang/node16/bin/node
console.log(__dirname)
const { nextStart } = require('next/dist/cli/next-start')
nextStart(['-p', '9000', '--hostname', '0.0.0.0'])

调用顺利

然而,成功部署,不代表就能正常使用😂,接口函数
image

访问失败:

腾讯云的路由有点坑,所有页面都是404
image

image

from notionnext.

SenLief avatar SenLief commented on May 30, 2024

看来是没戏了,估计路由也是问题很大,重点应该还是匹配度不够了。

from notionnext.

qcmuu avatar qcmuu commented on May 30, 2024

即便部署在腾讯云,也无法加快加载notion的内容,所以并不会快多少吧?

from notionnext.

SenLief avatar SenLief commented on May 30, 2024

即便部署在腾讯云,也无法加快加载notion的内容,所以并不会快多少吧?

notion的部署是拉取到本地渲染的,相当于静态的博客。

from notionnext.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.