简体   繁体   English

Web3 不会在 Azure 上编译

[英]Web3 will not compile on Azure

Steps to reproduce:重现步骤:

  1. In Visual Studio 2019 Community, create a new Basic Azure Node.js Express 4 Application (TypeScript).在 Visual Studio 2019 社区中,创建一个新的基本 Azure Node.js Express 4 应用程序 (TypeScript)。
  2. Npm install web3 npm 安装 web3
  3. Add a line 4 after import path = require('path');在 import path = require('path'); 之后添加第 4 行;

    var Web3 = require('web3'); var Web3 = require('web3');

  4. Run it locally to ensure that it works (it does)在本地运行它以确保它工作(确实如此)
  5. Publish it to Azure and watch the logs将其发布到 Azure 并查看日志

Expected Result预期结果

It should compile and run fine -- just as it did locally in step 4它应该可以正常编译和运行——就像它在第 4 步中在本地所做的那样

Actual Results (from Azure log stream)实际结果(来自 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. 2020 年 4 月 2 日星期四 17:31:57 GMT+0000(协调世界时):应用程序抛出了一个未捕获的异常并被终止:D:\\home\\site\\wwwroot\\node_modules\\web3-core-method\\src\\index.js :285.then(async function (receipt) {^^^^^SyntaxError: missing ) 在参数列表 Object.exports.runInThisContext (vm.js:76:16)at Module._compile (module.js:542:28) 之后在 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 对象。 (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)应用程序抛出了一个未捕获的异常并被终止:D :\\home\\site\\wwwroot\\node_modules\\web3-core-method\\src\\index.js:285.then(async function (receipt) {^^^^^SyntaxError: missing ) 在参数列表 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)在对象。 (D:\\home\\site\\wwwroot\\node_modules\\web3-core\\src\\extend.js:27:14)at Module._compile (module.js:570:32) (D:\\home\\site\\wwwroot\\node_modules\\web3-core\\src\\extend.js:27:14)at Module._compile (module.js:570:32)

I have looked at line 285 in \\node_modules\\web3-core-method\\src\\index.js and it looks fine.我查看了 \\node_modules\\web3-core-method\\src\\index.js 中的第 285 行,看起来不错。

I deleted my package-lock.json and my node_modules directory and npm installed again (not to mention that I did it on both the original project and the small test project).我删除了我的 package-lock.json 和我的 node_modules 目录并再次安装了 npm(更不用说我在原始项目小型测试项目上都这样做了)。

I'm at a loss here.我在这里不知所措。 Any suggestions?有什么建议?

I had the very same issue running the latest version of web3 (1.2.6) with react on my desktop, this error shows on importing web3 .我在桌面上运行最新版本的web3 (1.2.6) 时遇到了同样的问题,在导入web3显示此错误。

const Web3 = require('web3');

It's interesting to note that there is no issue if I write the same line in node interactive console and the object Web3 works properly.有趣的是,如果我在节点交互式控制台中编写相同的行并且对象Web3正常工作,则没有问题。

I change the web3 version to 1.0.0-beta.55 and it worked fine.我将web3版本更改为1.0.0-beta.55并且运行良好。 I hope that this is a bug to be fixed in the latest versions.我希望这是在最新版本中修复的错误。

PS: before I try changing web3 version I tried updating node from 8.9.4 to 13.12.0 but the error still persisted. PS:在我尝试更改web3版本之前,我尝试将节点从8.9.4更新到13.12.0但错误仍然存​​在。

So .所以 。 . . . . . . I finally figured it out.我终于弄明白了。

Azure, by default has an abysmally old version of Node -- and you can only upgrade it to 8.9.4 (while node 12.16.1 is the LTS version).默认情况下,Azure 有一个非常旧的 Node 版本——你只能将它升级到 8.9.4(而节点 12.16.1 是 LTS 版本)。

But upgrading by adding the configuration setting WEBSITE_NODE_DEFAULT_VERSION with a value of 8.9.4 will fix the problem.但是通过添加值为 8.9.4 的配置设置 WEBSITE_NODE_DEFAULT_VERSION 进行升级解决该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM