Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm error - verify that the package.json has a valid "main" entry

Tags:

node.js

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

like image 405
yappy twan Avatar asked Nov 09 '20 16:11

yappy twan


5 Answers

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

like image 80
Manuel Da Silva Avatar answered Oct 21 '22 02:10

Manuel Da Silva


For me removing my node_modules folder and running npm i solve the problem

like image 28
Wisnu Wijokangko Avatar answered Oct 21 '22 03:10

Wisnu Wijokangko


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.

like image 3
LMulvey Avatar answered Oct 21 '22 03:10

LMulvey


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
like image 3
jerald jacob Avatar answered Oct 21 '22 01:10

jerald jacob


  1. Delete node_modules
  2. Run "npm i"
  3. Fixed

For me, the cause was that I accidentally hit STRG + C while installing all the modules, which broke something.

like image 3
Schon wieder am pasten naja Avatar answered Oct 21 '22 02:10

Schon wieder am pasten naja