Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

前端项目无法运行 #515

Open
0x3c5ad opened this issue Oct 29, 2023 · 10 comments
Open

前端项目无法运行 #515

0x3c5ad opened this issue Oct 29, 2023 · 10 comments

Comments

@0x3c5ad
Copy link

0x3c5ad commented Oct 29, 2023

npm i 报错 node版本16.16.0
image

@0x3c5ad
Copy link
Author

0x3c5ad commented Oct 29, 2023

将本地的webpack清空后,将node版本降级为12.22.12,可以执行npm i,但是运行时报错
image

@0x3c5ad
Copy link
Author

0x3c5ad commented Oct 29, 2023

问题已解决

将该目录下的文件进行更改后,问题解决
node_modules/web3-utils/lib/utils.js
image
修改代码:
// var BN = require('bn.js');
// var numberToBN = require('number-to-bn');
// var utf8 = require('utf8');
// var ethereumjsUtil = require('@ethereumjs/util');
// var ethereumBloomFilters = require('ethereum-bloom-filters');
// var { keccak256 } = require('ethereum-cryptography/keccak.js');

var { keccak256 } = require('ethereum-cryptography/keccak.js');

var BN = require('bn.js');
var numberToBN = require('number-to-bn');
var utf8 = require('utf8');
var ethereumjsUtil = require('ethereumjs-util');
var ethereumBloomFilters = require('ethereum-bloom-filters');

运行成功的图片:
image

@phzou204
Copy link

release-1.5.3版本 node依赖安装后,无法运行和编译 node版本16.x

@phzou204
Copy link

var { keccak256 } = require('ethereum-cryptography/keccak.js');

var BN = require('bn.js'); var numberToBN = require('number-to-bn'); var utf8 = require('utf8'); var ethereumjsUtil = require('ethereumjs-util'); var ethereumBloomFilters = require('ethereum-bloom-filters');

按照上述修改,使用相同的nodejs版本未成功运行,请问还有别的配置项修改吗?

@phzou204
Copy link

var { keccak256 } = require('ethereum-cryptography/keccak.js');
var BN = require('bn.js'); var numberToBN = require('number-to-bn'); var utf8 = require('utf8'); var ethereumjsUtil = require('ethereumjs-util'); var ethereumBloomFilters = require('ethereum-bloom-filters');

按照上述修改,使用相同的nodejs版本未成功运行,请问还有别的配置项修改吗?

已解决。本质还是webpack loader 对es6的语法支持问题。解决方法1: 图题主ethereumjs-util的方式。2: 修改webpack loader

@phzou204
Copy link

var { keccak256 } = require('ethereum-cryptography/keccak.js');
var BN = require('bn.js'); var numberToBN = require('number-to-bn'); var utf8 = require('utf8'); var ethereumjsUtil = require('ethereumjs-util'); var ethereumBloomFilters = require('ethereum-bloom-filters');

按照上述修改,使用相同的nodejs版本未成功运行,请问还有别的配置项修改吗?

已解决。本质还是webpack loader 对es6的语法支持问题。解决方法1: 图题主ethereumjs-util的方式。2: 修改webpack loader

package-lock.json 真的需要提交下,版本及依赖关系随着时间真的会影响后续运行和编译

@0x3c5ad
Copy link
Author

0x3c5ad commented Oct 30, 2023

var { keccak256 } = require('ethereum-cryptography/keccak.js');
var BN = require('bn.js'); var numberToBN = require('number-to-bn'); var utf8 = require('utf8'); var ethereumjsUtil = require('ethereumjs-util'); var ethereumBloomFilters = require('ethereum-bloom-filters');

按照上述修改,使用相同的nodejs版本未成功运行,请问还有别的配置项修改吗?

应该会提示这个
image

然后按照给的提示安装npm install --save ethereumjs-util这个即可

@0x3c5ad
Copy link
Author

0x3c5ad commented Oct 30, 2023

var { keccak256 } = require('ethereum-cryptography/keccak.js');
var BN = require('bn.js'); var numberToBN = require('number-to-bn'); var utf8 = require('utf8'); var ethereumjsUtil = require('ethereumjs-util'); var ethereumBloomFilters = require('ethereum-bloom-filters');

按照上述修改,使用相同的nodejs版本未成功运行,请问还有别的配置项修改吗?

已解决。本质还是webpack loader 对es6的语法支持问题。解决方法1: 图题主ethereumjs-util的方式。2: 修改webpack loader

package-lock.json 真的需要提交下,版本及依赖关系随着时间真的会影响后续运行和编译

@0x3c5ad 0x3c5ad closed this as completed Oct 30, 2023
@0x3c5ad 0x3c5ad reopened this Oct 30, 2023
@imtypist
Copy link

var { keccak256 } = require('ethereum-cryptography/keccak.js');
var BN = require('bn.js'); var numberToBN = require('number-to-bn'); var utf8 = require('utf8'); var ethereumjsUtil = require('ethereumjs-util'); var ethereumBloomFilters = require('ethereum-bloom-filters');

按照上述修改,使用相同的nodejs版本未成功运行,请问还有别的配置项修改吗?

应该会提示这个 image

然后按照给的提示安装npm install --save ethereumjs-util这个即可

感谢,node14.x,1.5.5成功编译

@coffee377
Copy link

var { keccak256 } = require('ethereum-cryptography/keccak.js');
var BN = require('bn.js'); var numberToBN = require('number-to-bn'); var utf8 = require('utf8'); var ethereumjsUtil = require('ethereumjs-util'); var ethereumBloomFilters = require('ethereum-bloom-filters');

按照上述修改,使用相同的nodejs版本未成功运行,请问还有别的配置项修改吗?

已解决。本质还是webpack loader 对es6的语法支持问题。解决方法1: 图题主ethereumjs-util的方式。2: 修改webpack loader

package-lock.json 真的需要提交下,版本及依赖关系随着时间真的会影响后续运行和编译

根本问题在于作者未提交版本锁定文件,对于开源项目这是及其重要的。随着项目和依赖库的迭代,说不定哪天项目就跑步起来了
我这里拉的是 1.5.5 的代码,包管理用的是 yarn,将下面的版本依赖范围缩小

image
原来的会安装<2.0.0的最新版本,目前我的是 1.10.2 , 这些依赖里面用了一些 es2020 的语法特性

  • optional-chaining 可选链操作符 ?
  • nullish-coalescing-operator 空值合并 ??

而项目依赖的是 babel6, 未配置相应的转换插件

知道问题所在,处理方式就很多了,最简单易用的方式就是降级依赖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants