我的代码都在本地工作(运行Node 17.4.0)。
但是,正如我提到的这里,当我部署到Render.com的生产服务器(它表示Detected Node version 17.4.0 (与本地开发使用的版本相同)时,函数会抛出以下错误:
TypeError: (0 , crypto__WEBPACK_IMPORTED_MODULE_0__.randomUUID)(...).replaceAll is not a function。TypeError: (intermediate value).format(...).replaceAll is not a function at getShortLocalizedDate如何确保replaceAll能够在我的生产服务器上工作?
我认为Node从replaceAll开始就支持v15了。
发布于 2022-06-15 23:27:05
有些事情需要检查:您可能有其他东西覆盖engines.node中的Node版本集吗?根据https://render.com/docs/node-version,engines.node值将被
NODE_VERSION环境变量.node-version文件.nvmrc文件。此外,在呈现上部署时,是否选择Node作为环境
下面是一个用于呈现我创建的用于验证奇数节点版本号是否适用于呈现的小测试部署,以及验证replaceAll()在Nodev17.4.0中工作的测试。
代码(也在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"
}输出(也临时部署到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
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发布于 2022-06-15 20:28:44
https://render.com/docs/node-version似乎不完整。
我想知道渲染是否忽略奇数节点版本。
我已经在环境变量和package.json中指定了17.4.0,但是我仍然会看到部署日志上写着“DetectedNodeVersion18.3.0”,然后replaceAll仍然莫名其妙地无法工作。
最近,我在环境变量中指定了NODE_VERSION=18.3.0,甚至添加到package.json:"engines": { "node": ">=18.3.0 <19" },中。https://dashboard.render.com/web/srv-caevvv7ho1kse31neb0g/deploys/dep-cal3r7vh8vl4d0g8vujg的最新部署日志再次显示:Jun 15 04:16:34 PM ==> Detected Node version 18.3.0。
这次replaceAll起作用了!
所以我的解释是:
Detected Node version ___。它是神秘的。但我很高兴我的代码现在起作用了!
https://stackoverflow.com/questions/72637010
复制相似问题