NodeJS Web3js不会在Azure上编译

xghobddn  于 2023-01-12  发布在  Node.js
关注(0)|答案(2)|浏览(125)
Steps to reproduce:
  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');
  1. Run it locally to ensure that it works (it does)
  2. Publish it to Azure and watch the logs
Expected Result

It should compile and run fine -- just as it did locally in step 4
Actual Results (from Azure log stream)
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)
I have looked at line 285 in \node_modules\web3-core-method\src\index.js and it looks fine.
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).
I'm at a loss here. Any suggestions?

xyhw6mcr

xyhw6mcr1#

默认情况下,Azure有一个非常旧的Node版本, -您只能将其升级到8.9.4(而Node 12.16.1是LTS版本)。
但是,通过添加配置设置WEBSITE_NODE_DEFAULT_VERSION(值为8.9.4)* 进行升级 * 将修复此问题。

eqqqjvef

eqqqjvef2#

我在桌面上运行最新版本的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,但错误仍然存在。

相关问题