部署到render.com服务器时

发布于 2025-02-08 06:18:31 字数 751 浏览 1 评论 0 原文

我的代码都在本地起作用(运行节点17.4.0)。

但是正如我所提到的,检测到的节点版本17.4.0 (这与我用于本地开发的版本相同),函数丢弃错误:

  • typeError:(0,crypto__webpack_imported_module_0__。 Randomuuid)(...)。替换不是函数
  • typeError :(中间值).format(...)。替换不是getShortLocalizedDate的函数

我如何确保如何在生产服务器上使用 fellAceall 可以在我的生产服务器上工作?

ps我认为节点支持替换,因为 v15

My code all works locally (running Node 17.4.0).

But as I mentioned here, when I deploy to my production server at Render.com, which says Detected Node version 17.4.0 (which is the same version that I use for local development), functions throw errors like:

  • TypeError: (0 , crypto__WEBPACK_IMPORTED_MODULE_0__.randomUUID)(...).replaceAll is not a function.
  • TypeError: (intermediate value).format(...).replaceAll is not a function at getShortLocalizedDate

How can I ensure that replaceAll can work on my production server?

P.S. I think Node has supported replaceAll since v15.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七禾 2025-02-15 06:18:31

需要检查的某些内容:您是否还有其他内容覆盖 node.node 中的节点版本?根据 https://render.com/docs/node-version .Node 值将被

  1. node_version 环境变量
  2. a .node-version file 文件文件 file a repo
  3. a .nvmrc 。 >文件在您的存储库的根部。

另外,当您在渲染上部署时,您是否将节点选择为环境

这是我创建的一个小测试,以验证奇数节点版本编号在渲染上起作用,并验证 preplaceAll()在节点v17.4.0中起作用。

代码(也 https://github.com/crcastle/test-replaceall < /a>)

server.js

const http = require('http')


const requestListener = function (req, res) {
  const orig = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';

  const monkey = orig.replaceAll('dog', 'monkey');
  // expected output: "The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?"
  
  // global flag required when calling replaceAll with regex
  const regex = /Dog/ig;
  const ferret = orig.replaceAll(regex, 'ferret');
  // expected output: "The quick brown fox jumps over the lazy ferret. If the ferret reacted, was it really lazy?"

  const version = process.version;

  res.writeHead(200);
  res.end(`Original: ${orig}\nMonkey: ${monkey}\nFerret: ${ferret}\nI am Node version ${version}`);
};

const HOST = "0.0.0.0";
const PORT = process.env.PORT || 10000;
const server = http.createServer(requestListener);
server.listen(PORT, HOST, () => {
  console.log(`Server is listening on http://${HOST}:${PORT}`);
});

package.json

{
  "name": "test-replaceall",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "engines": {
    "node": "17.4.0"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

output (也临时部署到 https://test-replaceall.onrender.com

Original: The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?
Monkey: The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?
Ferret: The quick brown fox jumps over the lazy ferret. If the ferret reacted, was it really lazy?
I am Node version v17.4.0

构建和部署日志

Jun 15 04:07:08 PM  ==> Cloning from https://github.com/crcastle/test-replaceall...
Jun 15 04:07:09 PM ==> Checking out commit 17972cbecfdeafc0eb1c4a09cad07400ab5c8bc1 in branch main
Jun 15 04:07:25 PM ==> Detected Node version 17.4.0
Jun 15 04:07:26 PM ==> Running build command 'npm i'...
Jun 15 04:07:27 PM up to date, audited 1 package in 297ms
Jun 15 04:07:27 PM found 0 vulnerabilities
Jun 15 04:07:43 PM ==> Uploading build...
Jun 15 04:07:49 PM ==> Build successful

Some things to check: Do you maybe have something else overriding the Node version set in engines.node? According to https://render.com/docs/node-version, the engines.node value will be overridden by

  1. A NODE_VERSION environment variable
  2. A .node-version file at the root of your repo
  3. A .nvmrc file at the root of your repo.

Also, when you deploy on Render, are you selecting Node as the Environment?

Here's a small test deploy to Render I created to verify that odd Node version numbers work on Render and also to verify that replaceAll() works in Node v17.4.0.

Code (also at https://github.com/crcastle/test-replaceall)

server.js:

const http = require('http')


const requestListener = function (req, res) {
  const orig = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';

  const monkey = orig.replaceAll('dog', 'monkey');
  // expected output: "The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?"
  
  // global flag required when calling replaceAll with regex
  const regex = /Dog/ig;
  const ferret = orig.replaceAll(regex, 'ferret');
  // expected output: "The quick brown fox jumps over the lazy ferret. If the ferret reacted, was it really lazy?"

  const version = process.version;

  res.writeHead(200);
  res.end(`Original: ${orig}\nMonkey: ${monkey}\nFerret: ${ferret}\nI am Node version ${version}`);
};

const HOST = "0.0.0.0";
const PORT = process.env.PORT || 10000;
const server = http.createServer(requestListener);
server.listen(PORT, HOST, () => {
  console.log(`Server is listening on http://${HOST}:${PORT}`);
});

package.json:

{
  "name": "test-replaceall",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "engines": {
    "node": "17.4.0"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

Output (also temporarily deployed to https://test-replaceall.onrender.com)

Original: The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?
Monkey: The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?
Ferret: The quick brown fox jumps over the lazy ferret. If the ferret reacted, was it really lazy?
I am Node version v17.4.0

Build and deploy log

Jun 15 04:07:08 PM  ==> Cloning from https://github.com/crcastle/test-replaceall...
Jun 15 04:07:09 PM  ==> Checking out commit 17972cbecfdeafc0eb1c4a09cad07400ab5c8bc1 in branch main
Jun 15 04:07:25 PM  ==> Detected Node version 17.4.0
Jun 15 04:07:26 PM  ==> Running build command 'npm i'...
Jun 15 04:07:27 PM  up to date, audited 1 package in 297ms
Jun 15 04:07:27 PM  found 0 vulnerabilities
Jun 15 04:07:43 PM  ==> Uploading build...
Jun 15 04:07:49 PM  ==> Build successful ????
Jun 15 04:07:49 PM  ==> Deploying...
Jun 15 04:08:25 PM  ==> Detected Node version 17.4.0
Jun 15 04:08:25 PM  ==> Starting service with 'node server.js'
Jun 15 04:08:25 PM  Server is listening on http://0.0.0.0:10000
你的他你的她 2025-02-15 06:18:31

https://render.com/docs/node-version 似乎不完整。

我想知道渲染是否忽略了奇数的节点版本。

我在“环境变量”中指定了17.4.0,也指定了 package.json ,但我仍然看到部署日志说“检测到的节点版本18.3.0”,然后是>替换莫名其妙地行不通。

最近,我已经指定了 node_version = 18.3.0 在“环境变量”中,我什至添加到 package.json “发动机”:{”节点“:”&gt; = 18.3.0&lt; 19“},再次说:
Jun 15 04:16:34 pm ==&gt;检测到的节点版本18.3.0

这次替换有效!

因此,我的解释是:

  1. 检测到的节点版本___ 无法依靠部署日志中所示。
  2. 使用方法在

这是神秘的。但是我很高兴我的代码现在正在工作!

https://render.com/docs/node-version seems incomplete.

I wonder if Render ignores odd-numbered Node versions.

I'd specified 17.4.0 in the environment variables and also in package.json, but then I'd still see the deployment log say "Detected Node version 18.3.0", and then replaceAll inexplicably still wouldn't work.

More recently I've specified NODE_VERSION=18.3.0 in the environment variables, and I've even added to package.json: "engines": { "node": ">=18.3.0 <19" },. The latest deployment log at https://dashboard.render.com/web/srv-caevvv7ho1kse31neb0g/deploys/dep-cal3r7vh8vl4d0g8vujg again said:
Jun 15 04:16:34 PM ==> Detected Node version 18.3.0.

And this time replaceAll works!

So my interpretation is:

  1. The Detected Node version ___ shown in deployment logs cannot be relied upon.
  2. Specifying a Node version using methods at https://render.com/docs/node-version might not work unless their major version number is even (such as 18).

It's mysterious. But I'm glad my code is working now!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文