T460p机器上代码运行到 require('autobahn') 段时报如下错误:
"fatal" option is not supported on Node.js compiled without ICU
但是在mac、L470上运行均无错误,开始以为是node版本引起,后更改版本发现无差别。
经各种搜索未果,在github-crossbario/autobahn上提问无人问津:
https://github.com/crossbario/autobahn-js/issues/478
Codes under work well some times before, but never worknow : try { autobahn = require('autobahn'); } catch (e) { console.log("wamp_orbital.js.connectServer exception = " +e); return; } Exception occurs: wamp_orbital.js.connectServer exception = TypeError [ERR_NO_ICU]: "fatal" option is not supported on Node.js compiled without ICU Since I didn't meet such errors before, and I didn't change any code, maybe there is some difference in node-version or Electron-version, but I forgot corrent ones. node -v v12.10.0 electron 2.0.8 Anyone met the same problem as
遂开始进入node_modules中打印调试。
首先发现,问题异常发生在autobahn.js(v-18.3.2)的代码行为:
var cbor = require('cbor');
遂进入cbor库(v-5.0.1)中查询,发现异常发生在代码行:
exports.Commented = require('./commented')
继续进入cbor同目录下的commented.js文件中查询,发现异常代码行:
const utils = require('./utils')
继续进入cbor同目录下的utils.js文件中查询,发现异常代码行:
const td = new TD('utf8', {fatal: true, ignoreBOM: true})
其中,打印发现:
const TD = (typeof TextDecoder === 'function') ? TextDecoder : util.TextDecoder
使用了util.TextDecoder。
后检测发现,在L470中,可以正常运行的cbor版本为v-4.0.0,尝试手动在T460p上安装v-4.0.0版本的cbor后,原来的ICU报错不见了,但是出现新的问题:
wamp_orbital.js.connectServer connection = [object Object] could not create WAMP transport 'websocket': browser does not support WebSocket or WebSocket in Web workers could not create any WAMP transport
拷贝了一份L470下的完整node_moudles目录,运行时正常,开始尝试逐个替换测试:
1、autobahn
2、cbor
比对发现,autobahn中的Dockerfile有所区别:
L470可用版本中为 apt-get install -y npm nodejs-legacy T460p中不可用版本为 apt-get install -y npm nodejs nodejs-dev L470: autobahn "version": "18.10.2" T460p: autobahn "version": "18.3.2"
实际上在工程的package.json中,配置的autobahn版本为18.3.2,但是为何通过npm install自动安装了18.10.2版本呢?
手动安装autobahn 18.3.2版本得以解决问题:
npm install autobahn@18.3.2