[英]Error when using web3.js with Jest
When I run the following Jest test which uses the web3.js package 当我运行以下使用web3.js包的Jest测试时
const Web3 = require("web3");
test("Web3 version", function()
{
expect(Web3.version).toEqual("1.0.0-beta.23");
});
I get the following error 我收到以下错误
Cannot find module './build/Release/scrypt' from 'index.js'
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:191:17)
web3 appears to be installed correctly as the following correctly outputs Web3 version = 1.0.0-beta.23
web3似乎安装正确,因为以下正确输出
Web3 version = 1.0.0-beta.23
const Web3 = require("web3");
console.log("Web3 version = " + Web3.version);
I'm new to Jest (used it for the first time today) so I'm not sure if the problem is my Jest installation/setup or web3.js. 我是Jest的新手(今天第一次使用它)所以我不确定问题是我的Jest安装/设置还是web3.js.
I've created a simple project on GitHub to replicate the problem https://github.com/naddison36/web3-jest 我在GitHub上创建了一个简单的项目来复制问题https://github.com/naddison36/web3-jest
My machine is running Mac OS X 10.12.6
, node v6.10.3
and npm 3.10.10
. 我的机器运行的是Mac OS X
10.12.6
,节点v6.10.3
和npm 3.10.10
。 The test project is using web3.js version 1.0.0-beta.23
and Jest 21.2.1
测试项目使用web3.js版本
1.0.0-beta.23
和Jest 21.2.1
In your package.json add "node" to jest -> moduleFileExtensions should fix it. 在你的package.json中添加“node”到jest - > moduleFileExtensions应该修复它。
{... "jest": { "testRegex": "(/__tests__/.*|(\\\\.|/)(test|spec))\\\\.(jsx?|tsx?)$", "moduleFileExtensions": [ "ts", "tsx", "js", "jsx", "json", "node" ] } }
reference: https://facebook.github.io/jest/docs/en/configuration.html#modulefileextensions-array-string 参考: https : //facebook.github.io/jest/docs/en/configuration.html#modulefileextensions-array-string
作为解决方法,将此行require(“./ build / release / scrypt”)更改为'/node_modupt/scrypt/index.js'中的require(“scrypt”)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.