ACLClouds
ACLClouds

npm shows ENOENT: package.json is missing

Find the root of the project and avoid launching npm in the wrong folder. Move the project to the root rather than writing cd mon-projet && npm start.

ENOENT package.json means that npm is working in a folder that does not contain the manifest. The file may be missing, incorrectly named, or located in a subfolder after Git import.

Step-by-step procedure

  1. List root

    Open Files and look for package.json. Check that it is not in a folder created by the GitHub archive.

  2. Correct the order

    Move the project to the root rather than writing cd mon-projet && npm start: dependencies are only installed from the package.json at the root.

  3. Check name

    Package.json with a capital letter is not recognized under Linux.

  4. Create only if necessary

    Only use npm init for a new project; on an existing project, get the real manifest from the repository.

Minimal package.json example

{
  "name": "mon-bot",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "discord.js": "^14.16.0"
  }
}

What the platform reads

For a Node.js bot, package.json is read at the root of the bot, meaning the first level of the “Files” tab. It serves two purposes.

If the file sits one level lower, nothing is installed and the command cannot be guessed: the bot stops right at launch, with ENOENT or Cannot find module.

  • Installing dependencies: the dependencies list is installed at start, following package-lock.json, yarn.lock or pnpm-lock.yaml if one is present.
  • Finding the start command: the start script is used first, then the main field, then a common file such as index.js or bot.js.

Move the project back to the root

The most common case is a ZIP archive downloaded from GitHub: it contains a folder such as mon-bot-main, and the whole project ends up inside it after extraction. Open that folder in “Files”, select all its contents and move them to the first level, then delete the empty folder.

Do not upload the node_modules folder: the installation recreates it. In the “Startup” tab, leave “Start command” empty so automatic detection takes over again, or click “Use automatic detection” if an old command is saved there.

Check startup

Restart the bot. The console should show the dependency installation with npm install, then the command that was run, for example $ node index.js. If the command still points to the old subfolder, fix it in the “Startup” tab and restart once more.

Frequently asked questions

What does npm ERR! enoent Could not read package.json mean?

The start command calls npm, but no package.json exists in the folder where it runs. The next line of the error gives the path that was searched. Compare it with the real location of the file in “Files”: either the file is in a subfolder or it was never uploaded.

Why do I get npm ERR! Missing script: "start"?

This time package.json is found, but it has no start script while the command is npm start. Add the script to the scripts section, as in the example below, or enter node index.js directly in “Start command”.

My bot is written in Python, do I need package.json?

No. A Python bot declares its dependencies in requirements.txt and is launched with python. If the error appears anyway, the start command contains npm start by mistake: clear the “Start command” field to go back to automatic detection, which looks for bot.py or main.py at the root.

The file is at the root but the error persists, why?

Look at the exact name. package.json.txt, added by some editors on Windows, or Package.json are not recognised. Rename the file to package.json, all lowercase. Also check that its content is valid JSON: a stray comma causes EJSONPARSE instead of ENOENT.