CommonJS/Module Errors Feel Random?

Hey! I have two projects with an identical configuration. For some reason, one project will run while the other one will fail due to an ES Module error.

package.json and tsconfig.json of project that works:
# package.json
{
  "name": "assessment_server",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "dev": "ts-node src/index.ts"
  },
  "dependencies": {
    "@prisma/client": "^5.0.0",
    "cors": "^2.8.5",
    "express": "^4.18.2",
    "uuid": "^9.0.0"
  },
  "devDependencies": {
    "@types/cors": "^2.8.13",
    "@types/express": "^4.17.17",
    "@types/node": "^20.4.5",
    "@types/uuid": "^9.0.2",
    "prisma": "^5.0.0",
    "ts-node": "^10.9.1",
    "typescript": "^5.1.6"
  }
}

# tsconfig.json
{
    "compilerOptions": {
        "sourceMap": true,
        "outDir": "dist",
        "strict": true,
        "lib": [
            "esnext"
        ],
        "esModuleInterop": true
    }
}


package.json and tsconfig.json of project that does not work:
# package.json
{
  "name": "cli-test",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "dev": "ts-node src/index.ts"
  },
  "dependencies": {
    "chalk": "^5.3.0",
    "commander": "^11.0.0",
    "figlet": "^1.6.0"
  },
  "devDependencies": {
    "@types/figlet": "^1.5.6",
    "@types/node": "^20.4.5",
    "ts-node": "^10.9.1",
    "typescript": "^5.1.6"
  }
}

# tsconfig.json
{
    "compilerOptions": {
        "sourceMap": true,
        "outDir": "dist",
        "strict": true,
        "lib": [
            "esnext"
        ],
        "esModuleInterop": true
    }
}


The first project is basically the prisma-express.js example from their github repo.
The second project is just me trying to learn how to make a CLI app.
Was this page helpful?