Home > Net >  internal/modules/cjs/loader.js:456 throw e; ^ Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "export
internal/modules/cjs/loader.js:456 throw e; ^ Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "export

Time:10-02

After I run npm start

This is my result is ...

> nodefirebase_curd@1.0.0 start
> nodemon index.js

[nodemon] 2.0.13
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
internal/modules/cjs/loader.js:456
      throw e;
      ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in C:\Users\tong1\Desktop\test-Firebase\nodeFirebase_CURD\node_modules\firebase\package.json
    at throwExportsNotFound (internal/modules/esm/resolve.js:285:9)
    at packageExportsResolve (internal/modules/esm/resolve.js:508:3)
    at resolveExports (internal/modules/cjs/loader.js:450:36)
    at Function.Module._findPath (internal/modules/cjs/loader.js:490:31)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:888:27)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (C:\Users\tong1\Desktop\test-Firebase\nodeFirebase_CURD\db.js:1:18)
    at Module._compile (internal/modules/cjs/loader.js:1085:14) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
[nodemon] app crashed - waiting for file changes before starting...

I never see this error before...

This is the file that error mentioned. (This is \node_modules\firebase\package.json in my project.)

{
  "name": "firebase",
  "version": "9.1.0",
  "description": "Firebase JavaScript library for web and Node.js",
  "author": "Firebase <[email protected]> (https://firebase.google.com/)",
  "license": "Apache-2.0",
  "homepage": "https://firebase.google.com/",
  "keywords": [
    "authentication",
    "database",
    "Firebase",
    "firebase",
    "realtime",
    "storage",
    "performance",
    "remote-config"
  ],
  "files": [
    "**/dist/",
    "**/package.json",
    "/firebase*.js",
    "/firebase*.map",
    "compat/index.d.ts"
  ],
  "exports": {
    "./analytics": {
      "node": {
        "require": "./analytics/dist/index.cjs.js",
        "import": "./analytics/dist/index.mjs"
      },
      "default": "./analytics/dist/index.esm.js"
    },
    "./app": {
      "node": {
        "require": "./app/dist/index.cjs.js",
        "import": "./app/dist/index.mjs"
      },
      "default": "./app/dist/index.esm.js"
    },
    "./app-check": {
      "node": {
        "require": "./app-check/dist/index.cjs.js",
        "import": "./app-check/dist/index.mjs"
      },
      "default": "./app-check/dist/index.esm.js"
    },
    "./auth": {
      "node": {
        "require": "./auth/dist/index.cjs.js",
        "import": "./auth/dist/index.mjs"
      },
      "default": "./auth/dist/index.esm.js"
    },
    "./auth/cordova": {
      "node": {
        "require": "./auth/cordova/dist/index.cjs.js",
        "import": "./auth/cordova/dist/index.mjs"
      },
      "default": "./auth/cordova/dist/index.esm.js"
    },
    "./auth/react-native": {
      "node": {
        "require": "./auth/react-native/dist/index.cjs.js",
        "import": "./auth/react-native/dist/index.mjs"
      },
      "default": "./auth/react-native/dist/index.esm.js"
    },
    "./database": {
      "node": {
        "require": "./database/dist/index.cjs.js",
        "import": "./database/dist/index.mjs"
      },
      "default": "./database/dist/index.esm.js"
    },
    "./firestore": {
      "node": {
        "require": "./firestore/dist/index.cjs.js",
        "import": "./firestore/dist/index.mjs"
      },
      "default": "./firestore/dist/index.esm.js"
    },
    "./firestore/lite": {
      "node": {
        "require": "./firestore/lite/dist/index.cjs.js",
        "import": "./firestore/lite/dist/index.mjs"
      },
      "default": "./firestore/lite/dist/index.esm.js"
    },
    "./functions": {
      "node": {
        "require": "./functions/dist/index.cjs.js",
        "import": "./functions/dist/index.mjs"
      },
      "default": "./functions/dist/index.esm.js"
    },
    "./messaging": {
      "node": {
        "require": "./messaging/dist/index.cjs.js",
        "import": "./messaging/dist/index.mjs"
      },
      "default": "./messaging/dist/index.esm.js"
    },
    "./messaging/sw": {
      "node": {
        "require": "./messaging/sw/dist/index.cjs.js",
        "import": "./messaging/sw/dist/index.mjs"
      },
      "default": "./messaging/sw/dist/index.esm.js"
    },
    "./performance": {
      "node": {
        "require": "./performance/dist/index.cjs.js",
        "import": "./performance/dist/index.mjs"
      },
      "default": "./performance/dist/index.esm.js"
    },
    "./remote-config": {
      "node": {
        "require": "./remote-config/dist/index.cjs.js",
        "import": "./remote-config/dist/index.mjs"
      },
      "default": "./remote-config/dist/index.esm.js"
    },
    "./storage": {
      "node": {
        "require": "./storage/dist/index.cjs.js",
        "import": "./storage/dist/index.mjs"
      },
      "default": "./storage/dist/index.esm.js"
    },
    "./compat/analytics": {
      "node": {
        "require": "./compat/analytics/dist/index.cjs.js",
        "import": "./compat/analytics/dist/index.mjs"
      },
      "default": "./compat/analytics/dist/index.esm.js"
    },
    "./compat/app": {
      "node": {
        "require": "./compat/app/dist/index.cjs.js",
        "import": "./compat/app/dist/index.mjs"
      },
      "default": "./compat/app/dist/index.esm.js"
    },
    "./compat/app-check": {
      "node": {
        "require": "./compat/app-check/dist/index.cjs.js",
        "import": "./compat/app-check/dist/index.mjs"
      },
      "default": "./compat/app-check/dist/index.esm.js"
    },
    "./compat/auth": {
      "node": {
        "require": "./compat/auth/dist/index.cjs.js",
        "import": "./compat/auth/dist/index.mjs"
      },
      "default": "./compat/auth/dist/index.esm.js"
    },
    "./compat/database": {
      "node": {
        "require": "./compat/database/dist/index.cjs.js",
        "import": "./compat/database/dist/index.mjs"
      },
      "default": "./compat/database/dist/index.esm.js"
    },
    "./compat/firestore": {
      "node": {
        "require": "./compat/firestore/dist/index.cjs.js",
        "import": "./compat/firestore/dist/index.mjs"
      },
      "default": "./compat/firestore/dist/index.esm.js"
    },
    "./compat/functions": {
      "node": {
        "require": "./compat/functions/dist/index.cjs.js",
        "import": "./compat/functions/dist/index.mjs"
      },
      "default": "./compat/functions/dist/index.esm.js"
    },
    "./compat/messaging": {
      "node": {
        "require": "./compat/messaging/dist/index.cjs.js",
        "import": "./compat/messaging/dist/index.mjs"
      },
      "default": "./compat/messaging/dist/index.esm.js"
    },
    "./compat/performance": {
      "node": {
        "require": "./compat/performance/dist/index.cjs.js",
        "import": "./compat/performance/dist/index.mjs"
      },
      "default": "./compat/performance/dist/index.esm.js"
    },
    "./compat/remote-config": {
      "node": {
        "require": "./compat/remote-config/dist/index.cjs.js",
        "import": "./compat/remote-config/dist/index.mjs"
      },
      "default": "./compat/remote-config/dist/index.esm.js"
    },
    "./compat/storage": {
      "node": {
        "require": "./compat/storage/dist/index.cjs.js",
        "import": "./compat/storage/dist/index.mjs"
      },
      "default": "./compat/storage/dist/index.esm.js"
    }
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/firebase/firebase-js-sdk.git"
  },
  "scripts": {
    "build": "rollup -c && gulp cdn-type-module-path && yarn build:compat",
    "build:compat": "rollup -c compat/rollup.config.js",
    "dev": "rollup -c -w",
    "test": "echo 'No test suite for firebase wrapper'",
    "test:ci": "echo 'No test suite for firebase wrapper'"
  },
  "dependencies": {
    "@firebase/app": "0.7.1",
    "@firebase/app-compat": "0.1.2",
    "@firebase/app-types": "0.7.0",
    "@firebase/auth": "0.18.0",
    "@firebase/auth-compat": "0.1.3",
    "@firebase/database": "0.12.1",
    "@firebase/database-compat": "0.1.1",
    "@firebase/firestore": "3.1.0",
    "@firebase/firestore-compat": "0.1.3",
    "@firebase/functions": "0.7.2",
    "@firebase/functions-compat": "0.1.3",
    "@firebase/installations": "0.5.1",
    "@firebase/messaging": "0.9.1",
    "@firebase/messaging-compat": "0.1.1",
    "@firebase/polyfill": "0.3.36",
    "@firebase/storage": "0.8.3",
    "@firebase/storage-compat": "0.1.3",
    "@firebase/performance": "0.5.1",
    "@firebase/performance-compat": "0.1.1",
    "@firebase/remote-config": "0.3.0",
    "@firebase/remote-config-compat": "0.1.1",
    "@firebase/analytics": "0.7.1",
    "@firebase/analytics-compat": "0.1.2",
    "@firebase/app-check": "0.4.1",
    "@firebase/app-check-compat": "0.1.2",
    "@firebase/util": "1.4.0"
  },
  "devDependencies": {
    "rollup": "2.56.3",
    "@rollup/plugin-commonjs": "20.0.0",
    "@rollup/plugin-node-resolve": "13.0.4",
    "rollup-plugin-sourcemaps": "0.6.3",
    "rollup-plugin-terser": "7.0.2",
    "rollup-plugin-typescript2": "0.30.0",
    "rollup-plugin-uglify": "6.0.4",
    "gulp": "4.0.2",
    "gulp-sourcemaps": "3.0.0",
    "gulp-replace": "1.1.3",
    "typescript": "4.2.2"
  },
  "components": [
    "analytics",
    "app",
    "app-check",
    "auth",
    "auth/cordova",
    "auth/react-native",
    "functions",
    "firestore",
    "firestore/lite",
    "storage",
    "performance",
    "remote-config",
    "messaging",
    "messaging/sw",
    "database"
  ]
}

Another one. (This is .js file.)

const firebase = require('firebase');
const config = require('./config');

const db = firebase.initializeApp(config.firebaseConfig);

module.exports = db;

I try to fix it with myself but I don't know where to fix it. I try to search this problem on internet but I'm not found.

What should I do. Can you help me, please.

If you what to see more you can tell me.

Thank you so much.

CodePudding user response:

chnage the .js file to

const { initializeApp } = require('firebase/app')
const config = require('./config');

const db = initializeApp(config.firebaseConfig);

module.exports = db;

refer to firebase

  • Related