当我运行以下使用web3.js包的Jest测试时
const Web3 = require("web3");
test("Web3 version", function()
{
expect(Web3.version).toEqual("1.0.0-beta.23");
});
我得到以下错误
Cannot find module './build/Release/scrypt' from 'index.js'
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:191:17)
web3的安装似乎是正确的,因为下面正确地输出了Web3 version = 1.0.0-beta.23
const Web3 = require("web3");
console.log("Web3 version = " + Web3.version);
我是Jest的新手(今天第一次使用Jest ),所以我不确定问题是Jest安装/安装还是web3.js。
我在GitHub上创建了一个简单的项目来复制问题https://github.com/naddison36/web3-jest
我的机器正在运行Mac 10.12.6
、node v6.10.3
和npm 3.10.10
。测试项目使用web3.js版本的1.0.0-beta.23
和Jest 21.2.1
发布于 2017-10-11 00:25:14
在您的package.json中添加"node“来开玩笑,-> moduleFileExtensions应该修复它。
{... "jest": { "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", "moduleFileExtensions": [ "ts", "tsx", "js", "jsx", "json", "node" ] } }
参考资料:https://facebook.github.io/jest/docs/en/configuration.html#modulefileextensions-array-string
发布于 2019-05-16 11:17:18
作为一种解决办法,将这一行要求(“./build/require/scrypt”)更改为从'/node_modules/scrypt/index.js‘中要求(“scrypt”)。
https://stackoverflow.com/questions/46672532
复制相似问题