Cannot find module 'scrypt-shim' when using OpenZeppelin Test Environment

Running a vanilla install of Openzeppelin SDK and @openzeppelin/test-environment following the docs. When I try running a test I get a:

Error: Cannot find module 'scrypt-shim' error. (Full error below).

Using Mocha + Chai, stock OZ SDK setup + @openzeppelin/test-environment following the docs.

I also tested AVA to see if it was a problem with mocha, for a more succinct error message:


  Error: Cannot find module 'scrypt-shim'

  › Object.<anonymous> (node_modules/web3-eth-accounts/src/index.js:34:14)```

My setup:

  "dependencies": {
    "@openzeppelin/cli": "^2.8.2",
    "dotenv": "^8.2.0",
    "truffle-hdwallet-provider": "^1.0.17",
    "web3": "^1.2.9"
  },
  "devDependencies": {
    "@openzeppelin/test-environment": "^0.1.4",
    "@openzeppelin/test-helpers": "^0.5.6",
    "ava": "^3.9.0",
    "chai": "^4.2.0",
    "mocha": "^8.0.1"
  }

Complete error message:

Error: Cannot find module 'scrypt-shim'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:668:15)
    at Function.Module._load (internal/modules/cjs/loader.js:591:27)
    at Module.require (internal/modules/cjs/loader.js:723:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at Object.<anonymous> (/Users/dennisonbertram/Documents/dh-ABI-registry/node_modules/web3-eth-accounts/src/index.js:34:14)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)
    at Module.require (internal/modules/cjs/loader.js:723:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at Object.<anonymous> (/Users/dennisonbertram/Documents/dh-ABI-registry/node_modules/web3-eth/src/index.js:37:16)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)
    at Module.require (internal/modules/cjs/loader.js:723:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at Object.<anonymous> (/Users/dennisonbertram/Documents/dh-ABI-registry/node_modules/web3/src/index.js:33:11)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)
    at Module.require (internal/modules/cjs/loader.js:723:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at Object.<anonymous> (/Users/dennisonbertram/Documents/dh-ABI-registry/node_modules/@openzeppelin/test-environment/lib/accounts.js:7:32)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)
    at Module.require (internal/modules/cjs/loader.js:723:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at Object.<anonymous> (/Users/dennisonbertram/Documents/dh-ABI-registry/node_modules/@openzeppelin/test-environment/lib/helpers.js:8:20)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)
    at Module.require (internal/modules/cjs/loader.js:723:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at Object.<anonymous> (/Users/dennisonbertram/Documents/dh-ABI-registry/node_modules/@openzeppelin/test-environment/lib/index.js:6:35)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)
    at Module.require (internal/modules/cjs/loader.js:723:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at Object.<anonymous> (/Users/dennisonbertram/Documents/dh-ABI-registry/test/test.spec.js:1:32)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)
    at Module.require (internal/modules/cjs/loader.js:723:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at Object.exports.requireOrImport (/Users/dennisonbertram/Documents/dh-ABI-registry/node_modules/mocha/lib/esm-utils.js:20:12)
    at Object.exports.loadFilesAsync (/Users/dennisonbertram/Documents/dh-ABI-registry/node_modules/mocha/lib/esm-utils.js:33:34)
    at Mocha.loadFilesAsync (/Users/dennisonbertram/Documents/dh-ABI-registry/node_modules/mocha/lib/mocha.js:421:19)
    at singleRun (/Users/dennisonbertram/Documents/dh-ABI-registry/node_modules/mocha/lib/cli/run-helpers.js:156:15)
    at exports.runMocha (/Users/dennisonbertram/Documents/dh-ABI-registry/node_modules/mocha/lib/cli/run-helpers.js:225:10)
    at Object.exports.handler (/Users/dennisonbertram/Documents/dh-ABI-registry/node_modules/mocha/lib/cli/run.js:366:11)
    at innerArgv.then.argv (/Users/dennisonbertram/Documents/dh-ABI-registry/node_modules/yargs/lib/command.js:241:49)
    at process.runNextTicks [as _tickCallback] (internal/process/task_queues.js:52:5)
    at Function.Module.runMain (internal/modules/cjs/loader.js:880:11)
    at findNodeScript.then.existing (/Users/dennisonbertram/.nvm/versions/node/v11.15.0/lib/node_modules/npm/node_modules/libnpx/index.js:268:14)
1 Like

Hi @Dennison,

I am sorry that you are having this issue.

It looks like this was an issue with web3 1.2.3.

You could have a look to see if you have this version:

 npm ls web3@1.2.3

I wasn’t able to replicate using the Learn guide Writing Unit Tests and your dependencies:

{
  "name": "dennison",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "mocha --exit --recursive test"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@openzeppelin/cli": "^2.8.2",
    "dotenv": "^8.2.0",
    "truffle-hdwallet-provider": "^1.0.17",
    "web3": "^1.2.9"
  },
  "devDependencies": {
    "@openzeppelin/test-environment": "^0.1.4",
    "@openzeppelin/test-helpers": "^0.5.6",
    "ava": "^3.9.0",
    "chai": "^4.2.0",
    "mocha": "^8.0.1"
  },
  "description": ""
}

I am running on WSL2 using the following node/npm versions:

node --version
v10.21.0
npm --version
6.14.5

You could try removing package-lock.json and node_modules and reinstall the dependencies.


As an aside, I noticed that you were using truffle-hdwallet-provider which has been deprecated for @truffle/hdwallet-provider

Hi @Dennison,

Were you able to resolve the issue?