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

1

7

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?

Pray answered 28/3, 2020 at 16:34 Comment(0)
M
6

Try using:

import mysqlPromise from "mysql2/promise.js";
Mycetozoan answered 29/3, 2020 at 0:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.