部署Node.js程序至Heroku/RedHat Openshift Online时遇模块找不到错误
Hey there, let's work through this "Cannot find module './dnssec'" error together. Here are actionable steps to resolve the issue based on your environment (npm@5.6.0, node@v8.9.4, production mode):
1. Reinstall Dependencies Completely
Old versions of npm (like 5.6.0) sometimes leave incomplete or corrupted dependency installations. Let's start fresh:
# Delete existing dependencies and lock file rm -rf node_modules package-lock.json # Reinstall all dependencies npm install
This ensures every required package (including any that might include the dnssec module) is installed properly.
2. Verify the dnssec File/Folder Exists
The error means Node.js can't locate ./dnssec relative to your main.js file. Check:
- Navigate to the directory where
main.jsis located. Is there adnssec.jsfile, or a folder nameddnsseccontaining anindex.jsfile? - Double-check the import path in
main.js—Linux systems are case-sensitive, so make sure the spelling/capitalization matches exactly (e.g.,./Dnssecvs./dnssecwill fail). - If this is a third-party module (not your own code), it's likely a sub-dependency of one of your packages. If reinstalling didn't fix it, try updating the parent package that should include
dnssec.
3. Install All Dependencies (Including Dev Dependencies)
Since you're running in NODE_ENV=production, npm skips installing devDependencies by default. If dnssec was mistakenly added to devDependencies but is required for production, run:
npm install --production=false
This forces npm to install all listed dependencies, regardless of environment.
4. Clear npm Cache
Corrupted cache can cause installation issues in older npm versions. Let's clear it before reinstalling:
npm cache clean --force rm -rf node_modules package-lock.json npm install
If none of these steps work, double-check your package.json to ensure all required dependencies are listed, and confirm that the module path in your main.js import is correct.
内容的提问来源于stack exchange,提问作者Yukinoe

