Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: Module not found: Error: Can't resolve 'mongodb' in '...node_modules/typeorm/platform' #2486

Closed
giladmaker opened this issue Aug 5, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@giladmaker
Copy link

giladmaker commented Aug 5, 2021

Description 🐜

I am trying to run the Next CLI build command in a create-next-app project with Next Auth set up with the following configuration:

import NextAuth from 'next-auth'
import Providers from 'next-auth/providers'

export default NextAuth({
  providers: [
    Providers.Credentials({
        name: 'Credentials',
        credentials: {
          username: { label: "Username", type: "text", placeholder: "jsmith" },
          password: {  label: "Password", type: "password" }
        },
        async authorize(credentials, req) {
          if (req.body.username === ... && req.body.password === ...) {
            return { id: 1, name: 'testuser', email: 'testuser@test.com' };
          }
          return null;
        }
      })
  ]
})

The build fails with the error message:
ModuleNotFoundError: Module not found: Error: Can't resolve 'mongodb' in 'path/to/node_modules/typeorm/platform'

Note that the error message can vary in the db name between build attempts, e.g. :
ModuleNotFoundError: Module not found: Error: Can't resolve 'mysql' in 'path/to/node_modules/typeorm/platform'

Is this a bug in your own project?

No

How to reproduce ☕️

https://codesandbox.io/s/trusting-river-qvi59?file=/next.config.js

  • go to above Codesandbox link
  • run yarn build in terminal
  • expected: Next should generate a production build
  • actual: Next build fails with error: ModuleNotFoundError: Module not found: Error: Can't resolve 'mongodb' in 'path/to/node_modules/typeorm/platform'

Screenshots / Logs 📽

Screen Shot 2021-08-05 at 11 30 09 PM

Environment 🖥

System:
OS: Linux 5.4 Debian GNU/Linux 10 (buster) 10 (buster)
CPU: (8) x64 Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
Memory: 3.76 GB / 62.61 GB
Container: Yes
Shell: 5.0.3 - /bin/bash
Binaries:
Node: 14.16.1 - ~/.nvm/versions/node/v14.16.1/bin/node
Yarn: 1.22.10 - ~/.nvm/versions/node/v14.16.1/bin/yarn
npm: 6.14.12 - ~/.nvm/versions/node/v14.16.1/bin/npm
npmPackages:
next: ^11.0.0 => 11.0.1
next-auth: latest => 3.17.2
react: ^17.0.2 => 17.0.2

@giladmaker giladmaker added the bug Something isn't working label Aug 5, 2021
@giladmaker
Copy link
Author

Ok, just realized the issue resolves if I remove the "target: serverless" property from my next.config.js.
I am still trying to figure out if I need that property (currently reading through Next JS issues mentioning the lack of docs for it))
Would still be great to understand the root cause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants