Skip to content

Cannot build next-auth-example with target: serverless (typeorm) #2048

@andyjaar

Description

@andyjaar

Description 🐜

When I build the next-auth-example project with a couple of minor changes, I get:
ModuleNotFoundError: Module not found: Error: Can't resolve 'mongodb' in '/Users/andyhall/Documents/Git/sgt/next-auth-example-project/node_modules/typeorm/platform'
(sometimes mongodb is replaced by mysql or another DB provider from typeorm)

The changes are:

  1. Add barebones pages/api/[...nextauth].js file with no providers and DATABASE_URL commented out
  2. Set next.config.js to module.exports = { target: "serverless" };
  3. Clean env.local from unused values

When I run yarn build (also tested npm run build) I get the typeorm error.

How to reproduce ☕️

  • clone next-auth-example
  • yarn
  • echo 'module.exports = { target: "serverless" }' >next.config.js
  • set pages/api/[...nextauth].js to:
import NextAuth from "next-auth";
export default NextAuth({
    providers: [],
    secret: "test-secret",
    session: { jwt: true },
    jwt: {},
    pages: {},
    callbacks: {},
    events: {},
    debug: false,
});
  • run yarn build

Screenshots / Logs 📽

Although not from next-auth-example, I built a repo with the same problem:
https://gitlab.com/supergoteam/next-auth-serverless-test/

Environment 🖥

System:
OS: macOS 11.3.1
CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
Memory: 2.19 GB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 10.15.3 - /usr/local/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 6.13.4 - /usr/local/bin/npm
Browsers:
Chrome: 90.0.4430.212
Firefox: 87.0
Safari: 14.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    help-neededThe maintainer needs help due to time constraint/missing knowledgeupstreamThe issue dervies from one of next-auth dependencies

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions