Cannot find module 'fs-extra' when testing with Truffle - npm

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.

You need to add it to your package.json and install the package.
Either run
npm install --save fs-extra
The --save option will add it to the package.json for you.
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

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

Related

Yarn Install Error: Package subpath error

I am currently working on a project following the documentation in this github repo.
github repo
I first clone the repo into a folder. I then cd into the folder and do a run yarn install to get all dependencies. I get the following error. I have node v17.2.0 installed.
(base) Eddys-MacBook-Pro:avalanche-wallet-sdk eddyarce$ yarn install
yarn install v1.22.17
warning ../../../../../package.json: No license field
[1/5] 🔍 Validating package.json...
[2/5] 🔍 Resolving packages...
success Already up-to-date.
$ husky install && yarn build:prod
husky - Git hooks installed
yarn run v1.22.17
warning ../../../../../package.json: No license field
$ rollup -c --environment BUILD:production
Error loading `tslib` helper library.
[!] Error: Package subpath './package.json' is not defined by "exports" in /Users/eddyalvarado_1/Documents/GitHub/plasma-wallet-web3/js/avalanche-wallet-sdk/node_modules/rollup-plugin-typescript2/node_modules/tslib/package.json
Error: Package subpath './package.json' is not defined by "exports" in /Users/eddyalvarado_1/Documents/GitHub/plasma-wallet-web3/js/avalanche-wallet-sdk/node_modules/rollup-plugin-typescript2/node_modules/tslib/package.json
at new NodeError (node:internal/errors:371:5)
at throwExportsNotFound (node:internal/modules/esm/resolve:429:9)
at packageExportsResolve (node:internal/modules/esm/resolve:683:3)
at resolveExports (node:internal/modules/cjs/loader:482:36)
at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/eddyalvarado_1/Documents/GitHub/plasma-wallet-web3/js/avalanche-wallet-sdk/node_modules/rollup-plugin-typescript2/src/tslib.ts:11:23)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
https://github.com/ezolenko/rollup-plugin-typescript2/issues/286
Upgrade your tslib version (>=0.31.0) or downgrade your node version (<17.0.0)

How to update core-js to core-js#3 dependency?

While I was trying to install and setup react native, the precaution observed about the core-js version as update your core-js#... to core-js#3 But don't know how to update my core-js.
$ sudo react-native init AwesomeProject121
Password:
This will walk you through creating a new React Native project in /Users/amarnr1989/AwesomeProject121
Using yarn v1.13.0
Installing react-native...
yarn add v1.13.0
info No lockfile found.
[1/4] 🔍 Resolving packages...
warning react-native > create-react-class > fbjs > core-js#1.2.7: core-js#<2.6.5 is no longer maintained. Please, upgrade to core-js#3 or at least to actual version of core-js#2.
[2/4] 🚚 Fetching packages...
[----------------------------------------------------------------------------------------------------------------------------------------------------------] 0/601internal/modules/cjs/loader.js:584
throw err;
^
Error: Cannot find module '/Users/amarnr1989/AwesomeProject121/node_modules/react-native/package.json'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
at Function.Module._load (internal/modules/cjs/loader.js:508:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at checkNodeVersion (/usr/local/lib/node_modules/react-native-cli/index.js:306:21)
at run (/usr/local/lib/node_modules/react-native-cli/index.js:300:3)
at createProject (/usr/local/lib/node_modules/react-native-cli/index.js:249:3)
at init (/usr/local/lib/node_modules/react-native-cli/index.js:200:5)
at Object.<anonymous> (/usr/local/lib/node_modules/react-native-cli/index.js:153:7)
at Module._compile (internal/modules/cjs/loader.js:701:30)
Please Suggest
You update core-js with the following command:
npm install --save core-js#^3
If you read the React Docs you will find that the command is derived from when you need to upgrade React itself.
For npm
npm install --save core-js#^3
for yarn
yarn add core-js#^3
For ng9 upgraders:
npm i -g core-js#^3
..then:
npm cache clean -f
..followed by:
npm i
How about reinstalling the node module? Go to the root directory of the project and remove the current node modules and install again.
These are the commands : rm -rf node_modules npm install
OR
npm uninstall -g react-native-cli and
npm install -g react-native-cli
With this
npm install --save core-js#^3
you now get the error
"core-js#<3 is no longer maintained and not recommended for usage due to the number of
issues. Please, upgrade your dependencies to the actual version of core-js#3"
so you might want to instead try
npm install --save core-js#3
if you're reading this post June 9 2020.
Install
npm i core-js
Modular standard library for JavaScript. Includes polyfills for ECMAScript up to 2019: promises, symbols, collections, iterators, typed arrays, many other features, ECMAScript proposals, some cross-platform WHATWG / W3C features and proposals like URL. You can load only required features or use it without global namespace pollution.
Read: https://www.npmjs.com/package/core-js

npx webpack insists on installing webpack-cli but its already installed

I am attempting to run the command:
npx webpack
It tells me it needs webpack-cli and asks if it should install it, I say 'yes'. Then it gives me:
PS C:\_ljdev\webpack demo> npx webpack
npx: installed 321 in 11.89s
One CLI for webpack must be installed. These are recommended choices, delivered as separate packages:
- webpack-cli (https://github.com/webpack/webpack-cli)
The original webpack full-featured CLI.
We will use "npm" to install the CLI via "npm install -D".
Do you want to install 'webpack-cli' (yes/no): yes
Installing 'webpack-cli' (running 'npm install -D webpack-cli')...
npm WARN webpack-cli#3.2.3 requires a peer of webpack#4.x.x but none is installed. You must install peer dependencies yourself.
+ webpack-cli#3.2.3
updated 1 package and audited 1053 packages in 2.093s
found 0 vulnerabilities
{ Error: Cannot find module 'webpack-cli'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at runCommand.then (C:\Users\luke.jenner\AppData\Roaming\npm-cache\_npx\3272\node_modules\webpack\bin\webpack.js:143:5)
at process._tickCallback (internal/process/next_tick.js:68:7) code: 'MODULE_NOT_FOUND' }
So I attempt to install it locally, manually via:
PS C:\_ljdev\webpack demo> npm install webpack-cli
npm WARN webpack-cli#3.2.3 requires a peer of webpack#4.x.x but none is installed. You must install peer dependencies yourself.
+ webpack-cli#3.2.3
updated 1 package and audited 1053 packages in 8.034s
found 0 vulnerabilities
And I check that it is installed using:
PS C:\_ljdev\webpack demo> npm list
webpack-demo#1.0.0 C:\_ljdev\webpack demo
`-- webpack-cli#3.2.3
+-- chalk#2.4.2
| +-- ansi-styles#3.2.1
(other dependencies omitted for brevity)
So it appears installed.
I try npx webpack again and get the exact same output and question to install webpack-cli again.
Can anyone tell me why it's not finding the webpack-cli local install? Does it have to be installed globally?
Or more curiously: why does it fail when it tries to install it itself?
I have hit this error just recently.
Deleting the node_modules folder and reinstalling the dependencies with npm i made the npx webpack ... command work again. Can't really say why...
I have encountered the same problem.
After half a day of testing, I finally found out that there are special characters in my project path. Remove them, re-run npx webpack and everything is OK.
There is a space in your project path, maybe you can remove it and re-try.
click here to verify my result
Edit:
Sorry, I didn't express clearly. I meant that there were special characters in the project path which would be converted into some others during the npm installation.
If you change your working directory name, such as from webpack-demo to webpack/demo, remove and re-install webpack and webpack-cli. Then open the package.json of webpack package in node_modules directory, you will find the _where attribute which contains local absolute path but is different from your current real project path.
I guess(probably not right, maybe some other method) that npx command will use the _where attribute to locate the webpack package. So if the path is wrong, npm will have a tip that you should install webpack-cli first. But even you re-install the webpack-cli, the other scripts still can't find it.
Try running npx webpack-cli instead of npx webpack.
You need to install webpack-cli locally first using npm install --save-dev webpack-cli.
Try installing webpack-cli globally.
npm i -g webpack-cli
Go through this issue on github.
https://github.com/webpack/webpack-cli/issues/299

I can not update my npm version

Im using npm to update npm. It says that it updates it but the version stays the same (I have run this many times). Any help is appriciated.
felix:~/job (dev) $ npm --version
5.6.0
felix:~/job (dev) $ npm install npm#latest -g
/home/felix/.npm-global/bin/npm -> /home/felix/.npmglobal/lib/node_modules/npm/bin/npm-cli.js
/home/felix/.npm-global/bin/npx -> /home/felix/.npm-global/lib/node_modules/npm/bin/npx-cli.js
+ npm#6.1.0
updated 1 package in 4.939s
felix:~/job (dev) $ npm --version
5.6.0
I've also tried to do:
felix:~/job (dev) $ curl https://www.npmjs.com/install.sh | sh
module.js:549 curl https://www.npmjs.com/install.sh | sh
throw err;
^
Error: Cannot find module '/tmp/npm.30077/package/bin/read-package-json.js'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
removed 682 packages in 3.11s
/home/felix/.npm-global/bin/npm -> /home/felix/.npm-global/lib/node_modules/npm/bin/npm-cli.js
/home/felix/.npm-global/bin/npx -> /home/felix/.npm-global/lib/node_modules/npm/bin/npx-cli.js
+ npm#6.1.0
added 1 package from 572 contributors in 1.413s
It worked
felix:~/job (dev) $ npm --version
5.6.0
This also threw an error. And I'm not quite sure why.
I just had the exact same problem, even npm view npm version was returning 6.4.0 for me but npm -v still printed out 5.3.0.
Following this link: https://gist.github.com/DanHerbert/9520689 I uninstalled node from(with) Homebrew and reinstalled (still using Homebrew) it without npm, then installed npm separately, with official .sh.
That said, you mentioned that you have Linux, so that might not be the case with your issue, but this information might get you some ideas of what can be the case or help others, so posting in case :)
Good luck!

karma start Cannot find module 'jasmine-core'

I was getting the following error when I ran "karma start"
module.js:340
throw err;
^
Error: Cannot find module 'jasmine-core'
at Function.Module._resolveFilename (module.js:338:15)
at Function.require.resolve (module.js:384:19)
at initJasmine (/usr/lib/node_modules/karma-jasmine/lib/index.js:8:42)
at Array.invoke [as 0] (/usr/lib/node_modules/karma/node_modules/di/lib/injector.js:75:15)
at get (/usr/lib/node_modules/karma/node_modules/di/lib/injector.js:48:43)
at /usr/lib/node_modules/karma/lib/server.js:137:20
at Array.forEach (native)
at Server._start (/usr/lib/node_modules/karma/lib/server.js:136:21)
at invoke (/usr/lib/node_modules/karma/node_modules/di/lib/injector.js:75:15)
at Server.start (/usr/lib/node_modules/karma/lib/server.js:101:18)
at Object.exports.run (/usr/lib/node_modules/karma/lib/cli.js:231:26)
at Object. (/usr/lib/node_modules/karma/bin/karma:3:23)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
Does anyone know why this is happening? I was running karma in a VM. I tried several npm install commands and nothing worked. After I shutdown my machine for the night and came back the next day the problem went away and everything is working again. So, I'm not blocked anymore.. Anyone have some thoughts on what could be happening?
I solved using npm install jasmine-core --save-dev
try install jasmine-core globally (Jasmine on NPM).
use npm install -g jasmine-core
Even with karma and karma-jasmine installed in the local project's node_modules you must still npm install jasmine.
So for a fresh Karma project:
npm install karma karma-jasmine jasmine to install the required modules locally.
Optionally add --save-dev to write to your package.json.
Note these do not need to be -g globally installed here.
karma start
This step requires you to have Karma installed globally (sudo npm install -g karma).
Navigate to folder:
cd node_modules\karma-jasmine
Run:
npm install
This should download the required dependencies and fix the issue.
Also, it is important to know the installation path where do you have karma.conf.js file.
I have this problem, and have tried every suggestion on the page without it fixing the problem. Well, I haven't yet rebooted, so I'll try that next, but I have closed my shell (git-bash) and re-opened it in case it was an environment variable problem. Something is wrong here and I don't think the problem has been identified yet.