'npm error - verify that the package.json has a valid "main" entry
Im playing around with a simple trading bot using binance and cctx
when i run my script with node index.js
i get this long error:
internal/modules/cjs/loader.js:323
throw err;
^
Error: Cannot find module '/home/ether/Documents/nodesendeth/node_modules/cctx/index.js'. Please verify that the package.json has a valid "main" entry
at tryPackage (internal/modules/cjs/loader.js:315:19)
at Function.Module._findPath (internal/modules/cjs/loader.js:703:18)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:967:27)
at Function.Module._load (internal/modules/cjs/loader.js:862:27)
at Module.require (internal/modules/cjs/loader.js:1040:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/home/ether/Documents/nodesendeth/index.js:2:14)
at Module._compile (internal/modules/cjs/loader.js:1151:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
at Module.load (internal/modules/cjs/loader.js:1000:32) {
code: 'MODULE_NOT_FOUND',
path: '/home/ether/Documents/nodesendeth/node_modules/cctx/package.json',
requestPath: 'cctx'
}
so it basically cant find the cctx module
cctx was installed with npm i cctx and i also ran npm install afterwards just to make sure.
It also says verify that package.json file has a valid main entry, which it does:
{
"name": "nodesendeth",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"cctx": "^1.0.1",
"dotenv": "^8.2.0"
}
}
I pasted the code to my script here https://paste.ubuntu.com/p/p4n6MH3vbn/
Also my await functions arent working- even though i use them in an async function
So Im not a 100% sure what exactly the error is, there is a main entry in the package.json file and the cctx module has been installed
Solution 1:[1]
If you are working with firebase functions, and you are using TypeScript, check the path to the generated index.js after npm run build.
In my case it was lib/functions/src/main.js.
setting:
"main": "lib/functions/src/index.js",
on package.json fixed the issue
Solution 2:[2]
For me removing my node_modules folder and running npm i solve the problem
Solution 3:[3]
If you are working with firebase functions, and you are using TypeScript,
run the
npm run build
inside the Function directory
after that, a folder is generated in the current folder lib
then return back and fire!
$ firebase deploy
Solution 4:[4]
https://www.npmjs.com/package/cctx <- Not a valid package. It's a typo for this package: https://www.npmjs.com/package/ccxt (CCXT instead of CCTX). Install that instead. The issue isn't with your code, it's that you installed the wrong package.
Solution 5:[5]
In my case, I was getting this error from my VS Code ESLint plugin output. However running the linter through the terminal was just fine. After exhausting other options, restarting VS Code did the trick and ESLint plugin runs.
Solution 6:[6]
node:internal/modules/cjs/loader:361 throw err; ^
Error: Cannot find module '/Users/node_modules/express/server.js'. Please verify that the package.json has a valid "main" entry
fixed the above error - by making sure the express.js was added into my package.json as a dependency.
"dependencies": { "ejs": "^3.1.6", "express-ejs": "^2.0.0", "express-ejs-layouts": "^2.5.1", "express.js": "^1.0.0" },
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Manuel Da Silva |
| Solution 2 | Wisnu Wijokangko |
| Solution 3 | jerald jacob |
| Solution 4 | LMulvey |
| Solution 5 | logicalicy |
| Solution 6 | Tesla |
