5

I was reorganising documents on my mac and I have accidentally broken an app I am building. I noticed the package.json had been removed along with the router.js. I added both files back and the koa dependency in package.json to test.

CONSOLE ERROR

Error: No valid exports main found for '/Users/devunderdog/Work space/Fantasy_Sports_Manager_Server/node_modules/koa'

at resolveExportsTarget (internal/modules/cjs/loader.js:611:9)
at applyExports (internal/modules/cjs/loader.js:492:14)
at resolveExports (internal/modules/cjs/loader.js:541:12)
at Function.Module._findPath (internal/modules/cjs/loader.js:643:22)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:941:27)
at Function.Module._load (internal/modules/cjs/loader.js:847:27)
at Module.require (internal/modules/cjs/loader.js:1016:19)
at require (internal/modules/cjs/helpers.js:69:18)
at Object.<anonymous> (/Users/devunderdog/Work space/Fantasy_Sports_Manager_Server/index.js:1:13)
at Module._compile (internal/modules/cjs/loader.js:1121:30) {

  code: 'MODULE_NOT_FOUND'
}

INDEX.JS

const Koa = require('koa');
const app = new Koa();

This is where the "koa" require in index.js is trying to fetch the module. Incorrect module path

module "/Users/devunderdog/Library/Caches/typescript/3.9/node_modules/@types/koa/index"

PACKAGE.JSON

   {
      "name": "fantasy_sports_manager_server",
      "version": "1.0.0",
      "description": "A fantasy sports management system designed to help you pick the best players based on their return on investment.",
      "main": "index.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "author": "Lello De Luca",
      "license": "ISC",
      "dependencies": {
        "koa": "^2.13.0"
      }
    }

ALREADY TRIED

  • Removing /node_modules/ and npm install
  • Update NodeJS to v14.5.0
  • Removing and adding all required dependencies from package.json

Thanks in advance for any effort. Let me know if you need more code to reproduce.

Devunderdog

Devunderdog
  • 81
  • 1
  • 6

2 Answers2

2

I managed to fix the problem.

I believe I may have moved the root/.nvm directory by mistake and uninstalling and reinstalling has fixed that. The error is gone.

Let me know if anyone is not coming right and we could try to reproduce and fix the issue together.

Devunderdog
  • 81
  • 1
  • 6
1

Just removing node_module/ and reinstalling doesn't resolve this problem, upgrading node worked for me.

You can do this process manually, or with Homebrew if you’re using MacOS, or you may do it with linuxbrew on Windows.

  • run the following commands to upgrade Node version on macOS:

    $ brew update $ brew upgrade node

  • After Node was upgraded, run the following commands to remove and reinstall /node_modules/.

    $ rm -rf node_modules $ npm ci

npm ci to install the project with a clean slate.

annkkitt
  • 11
  • 3