【问题标题】:Node server stops working after several times working节点服务器多次工作后停止工作
【发布时间】:2019-09-04 03:08:00
【问题描述】:

我已经为我正在处理的 React 项目进行服务器端渲染的快速设置,并且在此进程之后的一段时间后它似乎异常停止工作:

1) 服务器上线,成功返回页面

2) 我稍微调整一下服务器文件,重新启动。

3) 服务器继续工作

4) 调整更多,重新启动

5) 服务器停止工作,即使恢复到步骤 1 中使用的文件

6) 附加错误将继续显示在以后的所有尝试中,直到删除 node_modules 并重新加载所有依赖项

因此,虽然我目前有一个解决方法,但每次出现这种情况时清除整个依赖集远非有效,而且我担心在部署应用程序时这种行为是否会出现。这是怎么回事,我该如何预防?

我已经确保节点没有在后台运行剩余的幽灵进程或其他任何东西,并且完整的运行日志与错误消息所说的没有太大不同。不确定这里要考虑的任何其他角度。

E:\JsProjects\ssrproj> npm run serve

> ssrproj@0.1.0 serve E:\JsProjects\ssrproj
> cross-env NODE_ENV=production node ./server/index.js

E:\JsProjects\ssrproj\node_modules\convert-source-map\index.js:61
  return SafeBuffer.Buffer.from(json, 'utf8').toString('base64');
                           ^

TypeError: Cannot read property 'from' of undefined
    at Converter.toBase64 (E:\JsProjects\ssrproj\node_modules\convert-source-map\index.js:61:28)
    at Converter.toComment (E:\JsProjects\ssrproj\node_modules\convert-source-map\index.js:65:21)
    at generateCode (E:\JsProjects\ssrproj\node_modules\@babel\core\lib\transformation\file\generate.js:78:76)
    at runSync (E:\JsProjects\ssrproj\node_modules\@babel\core\lib\transformation\index.js:50:51)
    at transformSync (E:\JsProjects\ssrproj\node_modules\@babel\core\lib\transform.js:43:38)
    at Object.transform (E:\JsProjects\ssrproj\node_modules\@babel\core\lib\transform.js:22:38)
    at compile (E:\JsProjects\ssrproj\node_modules\@babel\register\lib\node.js:73:20)
    at compileHook (E:\JsProjects\ssrproj\node_modules\@babel\register\lib\node.js:102:12)
    at Module._compile (E:\JsProjects\ssrproj\node_modules\pirates\lib\index.js:93:29)
    at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ssrproj@0.1.0 serve: `cross-env NODE_ENV=production node ./server/index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ssrproj@0.1.0 serve 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!     C:\Users\user\AppData\Roaming\npm-cache\_logs\2019-04-13T15_17_36_311Z-debug.log

【问题讨论】:

  • 看起来错误来自convert-source-map。考虑在生产中禁用它。

标签: javascript node.js express npm


【解决方案1】:

看起来此错误可能是由于 safe-buffer 项目中的竞争条件造成的,这似乎是 convert-source-map 项目的依赖项。其他人有a similar error when using safe-buffer。以下是我的建议。尝试任一:

  1. 确保您拥有 convert-source-map 和所有相关项目的最新版本
  2. 避免在生产中使用 convert-source-map。

【讨论】:

  • 使用它更新父项目似乎有效(间歇性问题很难快速确认),谢谢。无论哪种方式,听起来您对错误类型都是正确的。如果它是特定于平台的,可能不会被报道太多
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-26
  • 1970-01-01
相关资源
最近更新 更多