我正在 VPS 上运行我的项目并收到错误,但 http://localhost:3000/ 它可以工作,尝试卸载并安装 npm mongodb 但它不起作用。
删除 require('mongodb') 它可以在 VPS 上工作,但我不能使用 mongodb。
/Rest_api_2/node_modules/whatwg-url/dist/encoding.js:2
const utf8Encoder = new TextEncoder();
^
ReferenceError: TextEncoder is not defined
at Object.<anonymous> (Rest_api_2/node_modules/whatwg-url/dist/encoding.js:2:21)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (Rest_api_2/node_modules/whatwg-url/dist/url-state-machine.js:5:34)
at Module._compile (internal/modules/cjs/loader.js:778:30)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! rest_api_2@1.0.0 start: `node app.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the rest_api_2@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-08-29T14_07_03_848Z-debug.logRun Code Online (Sandbox Code Playgroud)
我有临时解决方案,我不知道它是错误还是什么,但为了让你的代码现在工作,我所做的是在 package.json 中,我将 mongoose 版本更改为 5.13.7 类似这样
"mongoose": "^5.13.7"
Run Code Online (Sandbox Code Playgroud)
然后删除node_modules并运行命令npm install以使用旧版本重新安装node_modules,然后我的代码运行
编辑:正如我所说的临时解决方案,我通过谷歌搜索找到了永久解决方案,实际上新版本的猫鼬需要新版本的nodejs,所以你只需要更新节点js和npm即可使其工作,并且其永久解决方案不只是降级从 mongoose 版本 5.13.7 到最新版本,使用它是暂时的,他们修复了一些漏洞,所以我建议最好的办法是更新 Node js 和 npm 并使用最新的 mongoose 版本。
| 归档时间: |
|
| 查看次数: |
3318 次 |
| 最近记录: |