admin管理员组

文章数量:1336632

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?

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?

Share Improve this question edited Mar 17, 2023 at 23:48 Mike asked Mar 28, 2020 at 16:34 MikeMike 14.6k32 gold badges120 silver badges177 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Try using:

import mysqlPromise from "mysql2/promise.js";

本文标签: javascriptCan39t import quotmysql2promisequot into ES module (MJS) on Nodejs 1314Stack Overflow