6

While migrating from CommonJS (.cjs) to ES Modules (.mjs), I've faced an issue of importing namespaced CJS to MJS:

import mysqlPromise from "mysql2/promise";

returns an error:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\Users\User\IdeaProjects\…\node_modules\mysql2\promise' imported from…

I checked checked the relevant thread ES Module support? Node 13, but don't see a clear solution.

Is there any way to import a namespaced CJS to ES Module/MJS?

Mike
  • 14,010
  • 29
  • 101
  • 161

1 Answers1

5

Try using:

import mysqlPromise from "mysql2/promise.js";
Luca Polito
  • 2,387
  • 14
  • 20