TypeScript to JavaScript

Hello Guys
when i create the project with ( npx create-next-app - - example mongodb Name of the project ) it will create the project for me but automatically the language is TypeScript how to change language to JavaScript ?

im not a huge fan of TypeScript i still love JavaScript to use

The example does not have heavy use of typescript. so there are only a few occurrences you need to check.

  • remove typescript specific packages: npm uninstall typescript @types/node @types/react
  • remove typescript configuration and types folder: rm -rf types tsconfig.json
  • rename index page: mv pages/index.tsx pages/index.jsx
    • then remove :InferGetServerSidePropsType<typeof getServerSideProps> from Home component function.
  • rename db file: mv lib/mongodb.ts lib/mongodb.js
    • then remove :Promise<MongoClient> from clientPromise decleration
1 Like

an alternative is to crawl old examples in old versions in the github repository and use that link as the example.

this following will install example in next-11 from a year ago:

npx create-next-app --example https://github.com/vercel/next.js/tree/next-11/examples/with-mongodb nextmongo

This got me the example code, but failed to install dependencies due to version changes to React. You will need to fix those dependencies by yourself.

PS: even though the size is small, this will be a bit slower to read files from GitHub.

what a beautiful explanation thanks alot dear