firebase / functions-samples

Collection of sample apps showcasing popular use cases using Cloud Functions for Firebase
https://firebase.google.com/docs/functions
Apache License 2.0
12k stars 3.83k forks source link

[BUG] in sample: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/v2/providers/scheduler' is not defined #1126

Closed Soolan closed 4 months ago

Soolan commented 4 months ago

Which sample has a bug?

You haven't provide a sample for scheduler

How to reproduce the issue

import {onSchedule} from 'firebase-functions/lib/v2/providers/scheduler';

Steps to set up and reproduce

The issue may be related to how the firebase-functions package is designed to work with ES modules and CommonJS modules. The error I encountered (ERR_PACKAGE_PATH_NOT_EXPORTED) suggests that the package has an issue with ES module resolution.

Debug output

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/v2/providers/scheduler' is not defined by "exports" in /functions/node_modules/firebase-functions/package.json at exportsNotFound (node:internal/modules/esm/resolve:302:10) at packageExportsResolve (node:internal/modules/esm/resolve:649:9) at resolveExports (node:internal/modules/cjs/loader:590:36) at Module._findPath (node:internal/modules/cjs/loader:667:31) at Module._resolveFilename (node:internal/modules/cjs/loader:1129:27) at Module._load (node:internal/modules/cjs/loader:984:27) at Module.require (node:internal/modules/cjs/loader:1234:19) at require (node:internal/modules/helpers:176:18) at Object. (/functions/build/functions/src/index.js:12:21) at Module._compile (node:internal/modules/cjs/loader:1375:14) { code: 'ERR_PACKAGE_PATH_NOT_EXPORTED' }

Expected behavior

It should import flawlessly

Actual behavior

It fails to import.

Workaround

use require instead of import. This works: // import {onSchedule} from 'firebase-functions/lib/v2/providers/scheduler'; const {onSchedule} = require("firebase-functions/v2/scheduler");

Soolan commented 4 months ago

Deleting node_modules and re-installing the packages solved the problem.