Unexpected Production Issue on Vercel: Works in Development, not in Production despite Reverting to a Working Commit

Everything works perfectly in the local development environment, but I encounter errors when the application is in production. The perplexing part is that I reverted to a previous commit where the production was working fine, and I still face the same problems.

Error Details:
The error messages mainly revolve around package subpaths not being defined by “exports” in different packages, and they look like this:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './cjs/stripe.cjs.node.js' is not defined by "exports" in /.../node_modules/stripe/package.json
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/index.cjs' is not defined by "exports" in /.../node_modules/express-rate-limit/package.json

I also encountered a ReferenceError: require is not defined in ES module scope error even though I am using ES6 import syntax in my JavaScript files. It’s being treated as an ES module due to the “type”: “module” in package.json, and it works locally.

Steps Taken:

  1. Reverted to a Working Commit:
    I have reverted to a commit when everything was working fine in production, but I still encounter the same errors.

  2. Checked Node.js Versions:
    Locally, I am using Node.js v19.6.1, while Vercel supports 18.x as default, and neither has changed recently.

  3. Reviewed Dependencies and Import Statements:
    I have reviewed my import statements and dependencies in package.json, ensuring they are correctly configured and locked to specific versions.

What could be causing this sudden issue in the production environment on Vercel even though everything works in the development environment, and no significant changes have been made?