Avatar ·

TypeScript त्रुटि: बिल्ड करते समय ReferenceError: exports is not defined

सभी को नमस्ते! मैं TypeScript में नया हूँ और अपने प्रोजेक्ट को कंपाइल और रन करने की कोशिश करते समय एक समस्या का सामना कर रहा हूँ। मैं Node.js (version 18) और TypeScript (version 5.0) का उपयोग कर रहा हूँ। यहाँ मेरा सरल कोड है:\n\n```typescript\n// math.ts\nexport function add(a: number, b: number): number {\n return a + b;\n}\n\nexport const PI = 3.14;\n```\n\n```typescript\n// main.ts\nimport { add, PI } from './math';\n\nconsole.log(add(2, 3));\nconsole.log(PI);\n```\n\nमैंने `tsc main.ts` कमांड से कोड कंपाइल किया और `math.js` और `main.js` फाइलें प्राप्त कीं। जब मैं `node main.js` चलाता हूँ, तो यह त्रुटि आती है:\n\n```\nReferenceError: exports is not defined\n at Object. (/path/to/main.js:2:23)\n```\n\nइसके अलावा, जनरेट की गई JS फाइलों में मैं `exports.add = ...` और `exports.PI = ...` का उपयोग देख रहा हूँ। मैंने पढ़ा है कि यह