我正在AWS上运行Kube集群,事情进展顺利。由于某种原因,我们的Node应用程序不断崩溃,我们从实例中获取以下重复日志....
我一直在寻找答案,但是我觉得很短暂,并且对于Node来说还是一个新手...有人能以正确的方式指导我调试吗?
谢谢!
[api-test-1214783129-8pg3b api-test] buffer.js:500
[api-test-1214783129-8pg3b api-test] throw new Error('"toString()" failed');
[api-test-1214783129-8pg3b api-test] ^
[api-test-1214783129-8pg3b api-test]
[api-test-1214783129-8pg3b api-test] Error: "toString()" failed
[api-test-1214783129-8pg3b api-test] at Buffer.toString (buffer.js:500:11)
[api-test-1214783129-8pg3b api-test] at Object.fs.readFileSync (fs.js:552:33)
[api-test-1214783129-8pg3b api-test] at Object.Module._extensions..js (module.js:549:20)
[api-test-1214783129-8pg3b api-test] at Module.load (module.js:458:32)
[api-test-1214783129-8pg3b api-test] at tryModuleLoad (module.js:417:12)
[api-test-1214783129-ii8f3 api-test] /code/src/core:1
[api-test-1214783129-ii8f3 api-test] (function (exports, require, module, __filename, __dirname) { ELF
[api-test-1214783129-ii8f3 api-test] ^
[api-test-1214783129-ii8f3 api-test] SyntaxError: Unexpected token ILLEGAL
[api-test-1214783129-ii8f3 api-test] at Object.exports.runInThisContext (vm.js:76:16)
[api-test-1214783129-ii8f3 api-test] at Module._compile (module.js:513:28)
[api-test-1214783129-ii8f3 api-test] at Object.Module._extensions..js (module.js:550:10)
[api-test-1214783129-ii8f3 api-test] at Module.load (module.js:458:32)
[api-test-1214783129-ii8f3 api-test] at tryModuleLoad (module.js:417:12)
[api-test-1214783129-ii8f3 api-test] at Function.Module._load (module.js:409:3)
[api-test-1214783129-ii8f3 api-test] at Function.cls_wrapMethod [as _load] (/code/src/node_modules/newrelic/lib/shimmer.js:257:38)
[api-test-1214783129-ii8f3 api-test] at Module.require (module.js:468:17)
[api-test-1214783129-ii8f3 api-test] at require (internal/module.js:20:19)
[api-test-1214783129-ii8f3 api-test] at Object.<anonymous> (/code/src/jsonwebtoken.js:10:12)
[api-test-1214783129-ii8f3 api-test] at Module._compile (module.js:541:32)
[api-test-1214783129-ii8f3 api-test] at Object.Module._extensions..js (module.js:550:10)
[api-test-1214783129-ii8f3 api-test] at Module.load (module.js:458:32)
[api-test-1214783129-ii8f3 api-test] at tryModuleLoad (module.js:417:12)
[api-test-1214783129-ii8f3 api-test] at Function.Module._load (module.js:409:3)
[api-test-1214783129-ii8f3 api-test] at Function.cls_wrapMethod [as _load] (/code/src/node_modules/newrelic/lib/shimmer.js:257:38)
[api-test-1214783129-ii8f3 api-test] error: Forever detected script exited with code: 1
[api-test-1214783129-ii8f3 api-test] error: Script restart attempt #86
答案 0 :(得分:3)
错误是说无法读取模块的源代码。具体来说,字节表示(Buffer
)无法转换为字符串。
如果您的代码未保存为纯UTF-8,则会发生这种情况。
在您的情况下,那是因为当节点执行require('./core');
时,它会查找文件core
,但会找到... core dump。要避免此问题,请执行以下任一操作或以下操作:
require('./core');
require('./core.js');
core.js
,并将相应的要求重命名为ourcore.js
和require('./ourcore');
/code/src/core
。这种解决方法只是暂时的。对于类似的错误消息,其他解释可能是:
较旧的节点版本(尽管不是节点v6.3.1)甚至偶然发现了BOM。在十六进制编辑器中打开文件,然后查看开始。所有这些字符都是ASCII吗?
您可以使用十六进制编辑器删除BOM - 只需删除前导非ASCII字符。或者,在编程文本编辑器中打开文件 - 例如sublime,vscode,kate,notepad2等 - 并将其保存为没有BOM的UTF-8。 功能