Currently, I am utilizing the powerful NestJs Framework alongside typescript.
My task involves incorporating two-factor authentication (SMS) using the Nexmo node library. You can find further information on their website:
During the development phase, everything functioned smoothly as expected.
However, upon attempting to build for production, an issue arose:
Error: Cannot find module 'nexmo'
To troubleshoot, I delved into researching this dilemma.
I began by studying the distinction between import and require.
The majority of my NestJs project relies on imports, but I recalled instances where require was employed without any issues – such as when integrating axios or xml2js.
Subsequently, I encountered individuals experiencing similar obstacles, which they managed to resolve by adjusting their tsconfig.json file. Some opted for "moduleResolution": "node", while others switched from "module": "commonjs" to either "module": "AMD" or "module": "ESNext".
Despite trying all these solutions, the error persisted, fluctuating between variations.
This led me to seek further insights through reading about module resolution within TypeScript: https://www.typescriptlang.org/docs/handbook/module-resolution.html
Unfortunately, none of these resources yielded a solution.
A colleague suggested exploring the possibility of installing typings, yet NestJs already employs @types, which is considered an advanced version of typings.
At present, I remain at an impasse. My understanding thus far suggests that the conversion of the project from ts to js is imperative, but for reasons unknown, NestJs encounters difficulty locating the nexmo library within the node_modules directory.
If you possess any guidance or can direct me towards a viable solution, it would be greatly appreciated.