3

I am reading the tutorial on Ethereum Pet Shop -- Your First DApp, everything seems ok until I test with truffle test with below error:

Error: Cannot find module 'fs-extra'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.call (/Users/.npm-global/lib/node_modules/truffle/node_modules/@truffle/debugger/dist/external "fs-extra":1:18)
at r (/Users/.npm-global/lib/node_modules/truffle/node_modules/@truffle/debugger/dist/webpack/bootstrap:19:22)
[...]
Truffle v5.2.4 (core: 5.2.4)
Node v10.16.0

I have tried some suggestions as in Module is extraneous npm, but the Error: Cannot find module 'fs-extra' insists.

nambk
  • 445
  • 3
  • 13

2 Answers2

1

You need to add it to your package.json and install the package.

  1. Either run

    npm install --save fs-extra
    

    The --save option will add it to the package.json for you.

  2. Or add it manually to the package.json section dependencies

    "dependencies": {
        "fs-extra": "^9.1.0"
    }
    

    and then install it

    npm install
    

    Version 9.1.0 is the current version according to npmjs

Petr Hejda
  • 40,554
  • 8
  • 72
  • 100
  • Thanks for your swift support! It worked: `TestAdoption ✓ testUserCanAdoptPet (138ms) ✓ testGetAdopterAddressByPetId (146ms) ✓ testGetAdopterAddressByPetIdInArray (182ms) 3 passing (12s)` – nambk Mar 17 '21 at 18:38
0

fs-extra-package should be delivered as part of truffle and I would not recommend installing it to the project.

To fix it on Ubuntu follow these steps:

# stop apps/tools that using truffle - ganache-cli, etc.

# uninstall truffle
sudo npm uninstall -g truffle

# install truffle again
sudo npm install -g truffle

# check that fs-extra packaged installed
ls -lh  /usr/local/lib/node_modules/truffle/node_modules | grep fs-extra
vladimir
  • 13,428
  • 2
  • 44
  • 70