Every time I ran Better Auth’s command-line tool in a new Next.js project, Node.js printed a warning before anything else: [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file … is not specified and it doesn't parse as CommonJS. The command still worked, but the warning came back on every run. Here’s what causes it and the one-line fix.
The short answer: add "type": "module" to your package.json, under "private": true,. Node.js then knows that your project’s files use import and export, and the warning goes away.
What I Was Doing
I was setting up Better Auth in a new Next.js 16 app for Part 2 of the Better Auth Tutorial. I had created lib/auth.ts, the file that holds Better Auth’s settings, and ran Better Auth’s command-line tool to create the database tables:
npx auth@latest migrate
The project came from create-next-app, and its package.json had no "type" field.
What I Expected
The list of tables and fields Better Auth would create, a question to confirm, and a success message.
What I Got
Node.js printed four lines of warning before Better Auth’s own output (the folder paths are shortened here):
npm notice run bookshop@0.1.0 npx
npm notice run 'auth' migrate
(node:11924) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///…/lib/auth.ts?_1 is not specified and it doesn't parse as CommonJS.
Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
To eliminate this warning, add "type": "module" to …/package.json.
(Use `node --trace-warnings ...` to show where the warning was created)
🔑 The migration will affect the following:
-> name, email, emailVerified, image, createdAt, updatedAt fields on user table.
-> expiresAt, token, createdAt, updatedAt, ipAddress, userAgent, userId fields on session table.
-> accountId, providerId, userId, accessToken, refreshToken, idToken, accessTokenExpiresAt, refreshTokenExpiresAt, scope, password, createdAt, updatedAt fields on account table.
-> identifier, value, expiresAt, createdAt, updatedAt fields on verification table.
✔ Are you sure you want to run these migrations? … yes
🚀 migration was completed successfully!

The migration itself worked, and the tables were created. The warning came back each time I ran the command.
What I Checked
The warning comes from Node.js itself, not from Better Auth: it starts with (node:11924), the process number of Node.js. Node.js’s own documentation explains both halves of the message:
- Node.js runs TypeScript files by default, and it decides whether a
.tsfile is CommonJS or an ES module the same way as for a.jsfile. Its TypeScript documentation says that to useimportandexport, you add"type": "module"to the nearestpackage.json(Determining module system (opens in a new tab)). - A file whose nearest
package.jsonhas no"type"field is “ambiguous”: Node.js first runs it as CommonJS, and when it findsimportorexport, it reads the file again as an ES module. The packages documentation says this costs performance and asks you to set the field (the “type” field (opens in a new tab)). lib/auth.tsstarts withimportlines, and the project’spackage.jsonhas no"type"field.
Why It Happens
Better Auth’s command-line tool reads your settings by loading lib/auth.ts with Node.js. With no "type" field, Node.js treats the file as CommonJS first. The first import line doesn’t parse as CommonJS, so Node.js reads the whole file again as an ES module and prints this warning to tell you that it guessed.
The Fix
Open package.json in the project folder, and add the "type" line under "private": true, at the top level of the file:
"private": true,
"type": "module",
This tells Node.js that every .js and .ts file in the project is an ES module, so it reads lib/auth.ts once, as an ES module, with no guess. Next.js kept working the same in my project: npm run dev and npm run build both ran normally with the new line.
After the Fix
I ran the same command again:
npx auth@latest migrate
npm notice run bookshop@0.1.0 npx
npm notice run 'auth' migrate
🚀 No migrations needed.

The warning is gone. It says “No migrations needed” because the first run had already created the tables.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Putting "type": "module" inside "scripts" or another section | Node.js only reads the field at the top level, so the warning stays | Add it at the top level, next to "private" |
Renaming lib/auth.ts to get rid of the warning | Better Auth’s command-line tool looks for a file named auth.ts | Keep the name and add the "type" field |
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| The warning names another file | Another file with import or export is loaded the same way | The same "type" field covers every file under that package.json |
| The warning is still there | The line went into a different package.json | Edit the package.json in the folder where you run the command |
FAQ
Is the warning harmful?
No. Node.js reads the file again and the command works. The cost is the extra reading, which Node.js’s documentation calls a performance cost.
Does “type”: “module” break Next.js?
It didn’t in my Next.js 16 project: the development server and the production build both worked the same with it.
Conclusion
The MODULE_TYPELESS_PACKAGE_JSON warning means Node.js had to guess whether a file is CommonJS or an ES module. One line in package.json, "type": "module", answers the question, and Better Auth’s command-line tool runs without it.
Additional Resources
- Determining module system (opens in a new tab) in the Node.js TypeScript documentation
- The “type” field (opens in a new tab) in the Node.js packages documentation
- CLI (opens in a new tab) in the Better Auth documentation
Related
- Better Auth Tutorial — Part 2: Set Up Better Auth in Next.js with PostgreSQL, where this warning came up
Better Auth, Next.js and other names mentioned are trademarks of their respective owners. JD Bots isn’t affiliated with or endorsed by Better Auth, Inc. or Vercel.
0 comments