执行truffle init命令报错求助:无法找到original-require模块
Hey Saurabh, sorry to hear you're hitting this snag as you dive into smart contract development. Let's work through fixing this original-require module error you're seeing when running truffle init:
First, let's recap the error you ran into for clarity:
Error: Cannot find module 'original-require' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15) at Function.Module._load (internal/modules/cjs/loader.js:475:25) at Module.require (internal/modules/cjs/loader.js:598:17) at require (internal/modules/cjs/helpers.js:11:18) at Object.
(C:\Users\sau...
This issue almost always comes down to version incompatibilities between Truffle and your older Node.js 9.11.1 installation or corrupted cached files from the initial install. Here's how to fix it step by step:
Step 1: Uninstall the problematic Truffle instance
First, remove the global Truffle package that's causing the conflict:
npm uninstall -g truffle
Step 2: Clear npm's cache to eliminate corrupted files
Sometimes npm caches broken partial packages, so let's wipe that cache clean to start fresh:
npm cache clean --force
Step 3: Install a Truffle version compatible with Node.js 9.11.1
Node.js 9 is quite outdated, so newer Truffle versions won't play nice with it. Instead, install a stable older version that supports Node.js 9—Truffle v4.1.14 is a reliable, well-tested choice here:
npm install -g truffle@4.1.14
Step 4: Verify the installation and test truffle init
Once the install finishes, confirm everything is set up correctly by checking the Truffle version:
truffle version
You should see output showing Truffle v4.1.14. Now run truffle init again in your project directory—it should execute without the module error.
Extra Troubleshooting Tip (Windows Users)
If you're still stuck, try opening your command prompt as an administrator before reinstalling Truffle. Windows sometimes restricts global package installations without elevated permissions, which can lead to incomplete installs that trigger this error.
内容的提问来源于stack exchange,提问作者Saurabh

