error TS2792: Cannot find module ‘moment’. Did you mean to set the ‘moduleResolution’ option to ‘node’, or to add aliases to the ‘paths’ option?

Got this error when trying to import moment into a TypeScript React (.tsx) module?

To fix the issue, you will need to adjust your tsconfig.json file and add "moduleResolution": "node" to your compilerOptions, so it looks like this:

{
  "compilerOptions": {
    ...
    "moduleResolution": "node",
    ...
  }
}

The "moduleResolution": "node" setting in tsconfig.json tells the TypeScript compiler to use Node.js module resolution logic when resolving module names. This allows the compiler to look for modules in the node_modules folder and use the package.json file in the same folder to determine which files to use for a given module.

Leave a Comment

Your email address will not be published. Required fields are marked *