Description :
Hello, I’m encountering a persistent issue deploying a Node.js app to Heroku where it fails to locate a specific module ./_shims/index.js from within the openai npm package. Below are the details and what I’ve tried so far:
Error Message:
`Error: Cannot find module ‘./_shims/index.js’
Require stack:
- /app/node_modules/openai/streaming.js
- /app/node_modules/openai/core.js
- /app/node_modules/openai/index.js
- /app/projects/my-app/utils/someScript.js
- /app/server.js
`
Environment:
Node.js version: 18.17.1
Heroku stack: Heroku-22
Deployment method: Git push to Heroku
Attempts to Resolve:
- Checked local node_modules/openai directory – the _shims folder exists with index.js.
- Ran heroku run bash and confirmed node_modules/openai does not contain _shims.
- Deleted node_modules and package-lock.json, cleared npm cache, and redeployed.
- Ensured package.json includes “openai”: “^x.x.x” with the correct version.
- Added “engines”: {“node”: “18.x”} to package.json
It seems like the deployment is not copying all the necessary module subdirectories/files. Could this be related to how Heroku caches builds or installs packages? How can I ensure that Heroku installs the package exactly as it is structured locally?
Thank you for any help or suggestions you can provide!
Attempts to Resolve:
- Checked local node_modules/openai directory – the _shims folder exists with index.js.
- Ran heroku run bash and confirmed node_modules/openai does not contain _shims.
- Deleted node_modules and package-lock.json, cleared npm cache, and redeployed.
- Ensured package.json includes “openai”: “^x.x.x” with the correct version.
- Added “engines”: {“node”: “18.x”} to package.json
Jay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.