Solidity
Truffle 框架“在嚴格模式之外尚不支持塊範圍的聲明”
我嘗試在 Elementary OS(Ubuntu 發行版)上通過 npm 安裝和使用 Truffle 框架。安裝沒有明顯問題,但是在執行任何命令時,例如“truffle init”或“truffle unbox metacoin”,我收到錯誤:
/usr/local/lib/node_modules/truffle/build/cli.bundled.js:64601 !function(e,t){ true?module.exports=t():"function"==typeof define&&define.amd?define("ganache",[],t):"object"==typeof exports?exports.ganache=t():e.ganache=t()}(global,function(){return function(e){var t={};function a(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,a),r.l=!0,r.exports}return a.m=e,a.c=t,a.d=function(e,t,n){a.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},a.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="",a.w={},a(a.s=1222)}([function(e,t,a){try{var n=a(1);if("function"!=typeof n.inherits)throw"";e.exports=n.inherits}catch(t){e.exports=a(1208)}},function(e,t){e.exports=__webpack_require__(3)},function(e,t){e.exports=__webpack_require__(0)},function(e,t SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:374:25) at Object.Module._extensions..js (module.js:417:10) at Module.load (module.js:344:32) at Function.Module._load (module.js:301:12) at Function.Module.runMain (module.js:442:10) at startup (node.js:136:18) at node.js:966:3
我認為這是與 ES5/6 的某種兼容性問題。但我不確定為什麼全新安裝會發生這種情況。
apt install npm
從來沒有為我正常工作。刪除它並按照此處所述安裝https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
npm uninstall -g truffle apt purge npm curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - sudo apt-get install -y nodejs npm i -g truffle