Web3 不会在 Azure 上编译

Web3 will not compile on Azure

重现步骤:

  1. In Visual Studio 2019 Community, create a new Basic Azure Node.js Express 4 Application (TypeScript).
  2. Npm install web3
  3. Add a line 4 after import path = require('path');

    var Web3 = require('web3');

  4. 运行 它在本地以确保它工作(确实如此)
  5. 将其发布到 Azure 并查看日志

预期结果

It should compile and run fine -- just as it did locally in step 4

实际结果(来自 Azure 日志流)

Thu Apr 02 2020 17:31:57 GMT+0000 (Coordinated Universal Time): Application has thrown an uncaught exception and is terminated:D:\home\site\wwwroot\node_modules\web3-core-method\src\index.js:285.then(async function (receipt) {^^^^^SyntaxError: missing ) after argument listat Object.exports.runInThisContext (vm.js:76:16)at Module._compile (module.js:542:28)at Object.Module._extensions..js (module.js:579:10)at Module.load (module.js:487:32)at tryModuleLoad (module.js:446:12)at Function.Module._load (module.js:438:3)at Module.require (module.js:497:17)at require (internal/module.js:20:19)at Object. (D:\home\site\wwwroot\node_modules\web3-core\src\extend.js:27:14)at Module._compile (module.js:570:32)Application has thrown an uncaught exception and is terminated:D:\home\site\wwwroot\node_modules\web3-core-method\src\index.js:285.then(async function (receipt) {^^^^^SyntaxError: missing ) after argument listat Object.exports.runInThisContext (vm.js:76:16)at Module._compile (module.js:542:28)at Object.Module._extensions..js (module.js:579:10)at Module.load (module.js:487:32)at tryModuleLoad (module.js:446:12)at Function.Module._load (module.js:438:3)at Module.require (module.js:497:17)at require (internal/module.js:20:19)at Object. (D:\home\site\wwwroot\node_modules\web3-core\src\extend.js:27:14)at Module._compile (module.js:570:32)

我查看了 \node_modules\web3-core-method\src\index.js 中的第 285 行,看起来不错。

我删除了我的包-lock.json 和我的 node_modules 目录并再次安装了 npm(更不用说我在原始项目 小测试项目)。

我在这里不知所措。有什么建议吗?

我的桌面上有 React 的 运行 最新版本 web3 (1.2.6),此错误显示在导入 web3.

const Web3 = require('web3');

有趣的是,如果我在节点交互式控制台中编写相同的行并且对象 Web3 正常工作,则没有问题。

我将 web3 版本更改为 1.0.0-beta.55 并且运行良好。希望这是最新版本修复的bug。

PS:在尝试更改 web3 版本之前,我尝试将节点从 8.9.4 更新为 13.12.0,但错误仍然存​​在。

所以。 . . .我终于明白了。

Azure,默认情况下有一个非常旧的 Node 版本——您只能将其升级到 8.9.4(而 Node 12.16.1 是 LTS 版本)。

但是通过添加值为 8.9.4 的配置设置 WEBSITE_NODE_DEFAULT_VERSION 进行升级将 解决问题。