This repository serves as a demonstration of an issue encountered when compiling TypeScript (TS) code to JavaScript (JS) using the Telegram Grammy framework. The problem arises with the incorrect behavior of imports in the generated JS files, despite following the documentation provided by the library.
After compiling TS to JS, the imports in the generated JS files do not behave as expected, leading to errors related to module resolution or missing imports.
- Clone this repository.
- Install dependencies (
npm install
). - Compile TypeScript to JavaScript (
npm run build
). - Start the application (
npm start
).
The imports in the generated JS files should be correctly resolved and functional according to the specifications provided by the Telegram Grammy framework.
The imports in the generated JS files do not behave as expected, leading to errors during runtime.
To resolve the issue, modify the TypeScript compiler options in tsconfig.json
and update npm scripts in package.json
as follows:
{
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"newLine": "lf",
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noUncheckedIndexedAccess": true,
"noUnusedParameters": true,
"strict": true,
"module": "CommonJS", // instead of "module": "ESNext", as described on https://grammy.dev/hosting/heroku#prerequisites
"target": "ESNEXT",
"moduleResolution": "node",
"outDir": "./dist",
"skipLibCheck": true
}
}
- Modify the TypeScript compiler options in tsconfig.json as described above.
- Update the npm scripts in package.json.
- Run npm install to install any necessary dependencies.
- Recompile the TypeScript code using npm run build.
- Start the application using npm start.
For further assistance or inquiries, feel free to reach out:
- Telegram: @drdev
This project is licensed under the MIT License. See the LICENSE file for details.