Fix error "The requested module does not provide an export named" when using TypeScript
29 NOV 2022
TYPESCRIPT
This error mostly occurs when you are using the wrong Node module type in your code. For me, all of my source code was written using ECMAScript modules, however I was receiving this error, so I was slightly confused.
It turned out that the error was in the tsconfig.json
file; all of the code was being compiled to CommonJS code even though it was written using ECMAScript modules.
You simply have to change the module
item in the file from CommonJS
to ES2022
, as follows:
"module": "ES2022"
After recompiling your TypeScript code to JavaScript, you should find that the code executes as expected.