त्रुटित्रुटि: मॉड्यूल ‘x’ नहीं खोजा जा सका (यामॉड्यूल ‘x’ या इसके संबंधित प्रकार की घोषणाएंटाइपस्क्रिप्ट में नहीं मिल सका) बेहद सामान्य है। इसके कई अलग-अलग कारण हैं – यहां बताया गया है कि प्रत्येक का निदान और समाधान कैसे किया जाए।
📋 Table of Contents
- कारण 1: पैकेज स्थापित नहीं
- कारण 2: गलत आयात पथ (सापेक्ष आयात)
- कारण 3: गुम प्रकार की घोषणाएँ (टाइपस्क्रिप्ट)
- कारण 4: tsconfig पथ उपनाम कॉन्फ़िगर नहीं
- कारण 5: ईएसएम बनाम कॉमनजेएस एक्सटेंशन मुद्दे
- कारण 6: मॉड्यूल स्थापित है लेकिन निर्मित नहीं है (मोनोरेपो/वर्कस्पेस)
- डायग्नोस्टिक चेकलिस्ट
- नोड का मॉड्यूल रिज़ॉल्यूशन – यह कैसे काम करता है
- अक्सर पूछे जाने वाले प्रश्न
- निष्कर्ष
कारण 1: पैकेज स्थापित नहीं
# The most common cause — you forgot to install it
npm install express
# Reinstall everything if node_modules is corrupted
rm -rf node_modules package-lock.json
npm install
# Verify it's actually in package.json
npm list express
कारण 2: गलत आयात पथ (सापेक्ष आयात)
// 🐛 Wrong path
import { helper } from './utils/helper'; // but file is at ./lib/helper
// ✅ Fix: correct the relative path
import { helper } from './lib/helper';
// Common mistakes:
// - Missing ./ for local files: import x from 'utils' looks in node_modules
// - Wrong case: ./Helper vs ./helper (case-sensitive on Linux!)
// - Missing file extension in ESM (see Cause 5)
कारण 3: गुम प्रकार की घोषणाएँ (टाइपस्क्रिप्ट)
# Error: Cannot find module 'lodash' or its corresponding type declarations
# The package works but has no bundled types. Install @types:
npm install --save-dev @types/lodash
# For packages that will never have types, declare them:
# create src/types/untyped-module.d.ts
declare module 'some-untyped-package';
कारण 4: tsconfig पथ उपनाम कॉन्फ़िगर नहीं
// You use import { x } from '@/utils' but it's not configured
// tsconfig.json — add path mapping
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
}
}
// For runtime (Node), you also need tsconfig-paths or a bundler:
// npm install -D tsconfig-paths
// node -r tsconfig-paths/register dist/index.js
// Or use tsx which handles this automatically
कारण 5: ईएसएम बनाम कॉमनजेएस एक्सटेंशन मुद्दे
// In ESM ("type": "module" in package.json), you MUST include .js extension
// even when importing .ts files:
// 🐛 Fails in ESM
import { helper } from './utils/helper';
// ✅ Correct in ESM
import { helper } from './utils/helper.js'; // yes, .js even for .ts source
// package.json
{
"type": "module"
}
// tsconfig.json
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "bundler" // or "nodenext"
}
}
कारण 6: मॉड्यूल स्थापित है लेकिन निर्मित नहीं है (मोनोरेपो/वर्कस्पेस)
# In a monorepo, the dependency package hasn't been built yet
# Cannot find module '@myorg/shared'
# Build the dependency first
npm run build --workspace=@myorg/shared
# Or build all packages (Turborepo/Nx)
turbo build
npx nx run-many --target=build
डायग्नोस्टिक चेकलिस्ट
- क्या यह स्थापित है? भागो
npm list <module> - क्या रास्ता सही है? केस संवेदनशीलता और सापेक्ष पथ की जाँच करें
- क्या इसे @types की आवश्यकता है? प्रयास करें
npm i -D @types/<module> - ईएसएम मुद्दा? जोड़ें
.jsएक्सटेंशन यदि"type": "module" - पथ उपनाम? Tsconfig की जाँच करें
pathsऔर रनटाइम रिज़ॉल्वर - टीएस सर्वर को पुनरारंभ करें आपके संपादक में (वीएस कोड: Cmd+Shift+P, फिर “TS सर्वर पुनरारंभ करें”)
नोड का मॉड्यूल रिज़ॉल्यूशन – यह कैसे काम करता है
// import 'foo' (no ./) → Node looks in:
// 1. Core modules (fs, path, http)
// 2. node_modules in current dir
// 3. node_modules in parent dirs, up to root
// import './foo' (with ./) → resolves relative to current file
// Looks for: ./foo.js, ./foo.json, ./foo/index.js, etc.
// Understanding this explains most "cannot find module" errors:
// - No ./ means Node searches node_modules (fails if it's a local file)
// - ./ means relative path (fails if the path is wrong)
अक्सर पूछे जाने वाले प्रश्न
प्रश्न: यह स्थानीय स्तर पर क्यों काम करता है लेकिन सर्वर/सीआई पर विफल हो जाता है?
उ: आमतौर पर केस संवेदनशीलता – मैकओएस/विंडोज़ केस-असंवेदनशील होते हैं, लिनक्स नहीं। ./Helper स्थानीय रूप से काम करता है लेकिन यदि फ़ाइल./helperहै तो लिनक्स पर विफल रहता है . हमेशा सटीक मामले का मिलान करें.
प्रश्न: मैंने पैकेज स्थापित किया लेकिन अभी भी त्रुटि मिल रही है। क्यों?
उ: अपने संपादक के टाइपस्क्रिप्ट सर्वर, या डेव सर्वर को पुनरारंभ करें। यह भी जांचें कि पैकेजdependenciesमें है , न केवल सहेजे बिना स्थानीय रूप से स्थापित किया गया। यदि अनिश्चित हो तो नोड_मॉड्यूल हटाएं और पुनः इंस्टॉल करें।
प्रश्न: मॉड्यूल त्रुटि और प्रकार घोषणा त्रुटि के बीच क्या अंतर है?
ए: अकेले “मॉड्यूल नहीं मिल सका” = जेएस मॉड्यूल नहीं मिला। “…या इसके अनुरूप प्रकार की घोषणाएँ” = मॉड्यूल मौजूद है लेकिन टाइपस्क्रिप्ट प्रकार नहीं ढूँढ सकता। दूसरी की जरूरत है@types/x या एक.d.ts घोषणा।
प्रश्न: मैं डॉकर बिल्ड में इसे कैसे ठीक करूं?
ए: सुनिश्चित करेंnpm install कंटेनर के अंदर चलता है (होस्ट नोड_मॉड्यूल की प्रतिलिपि न बनाएं)। पहले package.json को कॉपी करें, इंस्टॉल करें, फिर सोर्स को कॉपी करें – इससे डॉकर लेयर कैशिंग में भी सुधार होता है।
प्रश्न: क्या मुझे “मॉड्यूलरिज़ॉल्यूशन”: “नोड” या “बंडलर” का उपयोग करना चाहिए?
ए: 2026 में,"bundler"का उपयोग करें Vite/esbuild/webpack (कोई एक्सटेंशन आवश्यक नहीं), या"nodenext"के साथ निर्मित परियोजनाओं के लिए शुद्ध नोड ईएसएम (एक्सटेंशन आवश्यक) के लिए। विरासत से बचें"node" नई परियोजनाओं के लिए.
निष्कर्ष
“मॉड्यूल नहीं खोजा जा सका” लगभग हमेशा इनमें से एक पर आता है: पैकेज स्थापित नहीं है, आयात पथ गलत है (मामले की जांच करें!), गायब@types, ईएसएम एक्सटेंशन आवश्यकताएँ, या अपुष्ट पथ उपनाम। डायग्नोस्टिक चेकलिस्ट पर ऊपर से नीचे तक काम करें –npm list, पथ सत्यापित करें,@typesकी जांच करें , और अपने टीएस सर्वर को पुनरारंभ करें। नब्बे प्रतिशत मामले पहले तीन चरणों में हल हो जाते हैं।
🔗 Share this article
✍️ Leave a Comment