You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows10下运行Node server.js遇TypeError问题求助(MERN教程)

MERN栈启动服务时MongoDB连接字符串未定义错误

我在Windows 10系统上跟随MERN栈教程操作,执行Node server.js命令时出现如下错误:

C:\xampp\htdocs\test1\mern\server\node_modules\mongodb-connection-string-url\lib\index.js:9
return (connectionString.startsWith('mongodb://') ||

TypeError: Cannot read properties of undefined (reading 'startsWith')
at connectionStringHasValidScheme (C:\xampp\htdocs\test1\mern\server\node_modules\mongodb-connection-string-url\lib\index.js:9:30)

后续还有更多at相关报错信息,未出现预期的启动结果:

Server is running on port: 5000
Successfully connected to MongoDB.

该问题曾在Stack Overflow提问但未得到解答,我的Node版本为v18.12.1,Java版本为java 19.0.1 2022-10-18。查看报错文件中的函数定义如下:

function connectionStringHasValidScheme(connectionString) {
    return (connectionString.startsWith('mongodb://') ||
        connectionString.startsWith('mongodb+srv://'));
}

我是MERN栈新手,恳请各位提供帮助。

内容的提问来源于stack exchange,提问作者Krabs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 07:05:19