Mike
Mike

Reputation: 14584

Can't import "mysql2/promise" into ES module (MJS) on Node.js 13 / 14

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?

Upvotes: 7

Views: 6106

Answers (1)

Luca Polito
Luca Polito

Reputation: 2862

Try using:

import mysqlPromise from "mysql2/promise.js";

Upvotes: 6

Related Questions