sidorares / sidorares/node-mysql2

Module not found: Can't resolve 'cardinal' in '//node_modules/mysql2/lib'

Open
#1,992 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
4.4k
Forks
680
Avg merge
9h 7m
Merged PRs (30d)
59

Description

When importing a wrapper function for the mysql2 package into the NextJS 13 /app directory I get this error:

Module not found: Can't resolve 'cardinal' in '//node_modules/mysql2/lib'

I dont get this error when importing inside the /pages directory.

Are there any conflicts with this package and the new server side app directory in NextJS 13

I'm importing this wrapper
import mysql from "mysql2/promise";

/lib/lib.js to /app/page.js

export async function query({ query, values = [] }) {
  const dbconnection = await mysql.createConnection({
    host: process.env.MYSQL_DB_HOST,
    database: process.env.MYSQL_DB_NAME,
    port: process.env.MYSQL_DB_PORT,
    user: process.env.MYSQL_DB_USER,
    password: process.env.MYSQL_DB_PWD,
  });
  try {
    const [results] = await dbconnection.execute(query, values);
    dbconnection.end();
    return results;
  } catch (error) {
    throw Error(error.message);
    return { error };
  }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the import from /lib/lib.js into /app/page.js in a NextJS 13 app, then compare it with the working /pages directory case. Inspect how mysql2/promise resolves the cardinal dependency under the app directory; done means the wrapper loads there without the reported module-not-found error.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, nextjs, node.js
Domain
backend, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.