whoots-js icon indicating copy to clipboard operation
whoots-js copied to clipboard

Wrong main entry in package.json?

Open endolith opened this issue 2 years ago • 0 comments

I don't know anything about this stuff, ChatGPT is trying to help me set up a server:

$ npm run start

> @mapbox/[email protected] start
> node server.js

node:internal/modules/cjs/loader:437
      throw err;
      ^

Error: Cannot find module '/home/ec2-user/whoots-js/index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (node:internal/modules/cjs/loader:429:19)
    at Module._findPath (node:internal/modules/cjs/loader:642:18)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1011:27)
    at Module._load (node:internal/modules/cjs/loader:870:27)
    at Module.require (node:internal/modules/cjs/loader:1091:19)
    at require (node:internal/modules/cjs/helpers:121:18)
    at Object.<anonymous> (/home/ec2-user/whoots-js/server.js:3:14)
    at Module._compile (node:internal/modules/cjs/loader:1189:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1243:10)
    at Module.load (node:internal/modules/cjs/loader:1067:32) {
  code: 'MODULE_NOT_FOUND',
  path: '/home/ec2-user/whoots-js/package.json',
  requestPath: './'
}

Node.js v18.12.1

The error mentions server.js because that's the script you're trying to run with npm run start. However, inside server.js, it seems like there's a require('./') or similar statement that's trying to load the main module specified in package.json, which is set to index.js.

The error is essentially saying: "I tried to run server.js, and server.js is asking for the main module specified in package.json, but I can't find that module."

To fix this, you can:

  1. Check server.js for a require('./') or similar statement and understand what it's trying to import. If it's not necessary, consider removing or modifying that line.
  2. Make sure the main field in your package.json points to a valid entry file, which in your case seems to be server.js.

After making these changes, try running npm run start again.


The line var WhooTS = require('./'); is trying to require the main module specified in your package.json, which is set to index.js. Since index.js doesn't exist in your directory, you're getting the error.

You have two options to fix this:

  1. Change the require('./') to point to the actual WhooTS library file. If the main WhooTS file is index.mjs, then change it to require('./index.mjs').

  2. Update the main field in your package.json to point to the correct main file, which in your case seems to be index.mjs.

After making one of these changes, try running npm run start again.

endolith avatar Aug 30 '23 17:08 endolith