question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crash on AWS Amplify build: "Building SSR... can't find mongodb"

See original GitHub issue

Description 🐜

Hi! When building my project on AWS Amplify, the build crashes with complaints for missing mongodb in typeorm. Build logs are below. This doesn’t occur locally.

Not sure why this is happening as I don’t use any database in my Next Auth configuration. I saw issue #2358 but I’m not doing any transpilation in my project.

Please let me know if there is more context I could give!

Is this a bug in your own project?

No

How to reproduce ☕️

This is my [...nextauth].js file. I also want to note that my project uses TypeScript for mostly everything else but I left NextAuth in JavaScript for simplicity.

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

const GOOGLE_NEEDED_SCOPES = [
  'https://www.googleapis.com/auth/userinfo.profile',
  'https://www.googleapis.com/auth/userinfo.email ',
  'https://www.googleapis.com/auth/business.manage',
  'https://www.googleapis.com/auth/admin.directory.user',
].join(' ')

export default NextAuth({
  providers: [
    Providers.Google({
      clientId: process.env.CLIENT_ID,
      clientSecret: process.env.CLIENT_SECRET,
      scope: GOOGLE_NEEDED_SCOPES,
      authorizationUrl:
        'https://accounts.google.com/o/oauth2/v2/auth?prompt=consent&access_type=offline&response_type=code',
      accessTokenUrl: 'https://oauth2.googleapis.com/token',
    }),
  ],

  callbacks: {
    async jwt(token, user, account, profile, isNewUser) {
      if (account?.accessToken) {
        token.accessToken = account.accessToken
        token.refreshToken = account.refreshToken
      }

      return token
    },

    async session(session, token) {
      session.accessToken = token.accessToken
      session.refreshToken = token.refreshToken

      return session
    },
  },

  secret: process.env.NEXT_AUTH_SECRET,
})

and here is my next.config.js:

module.exports = {
  reactStrictMode: true,
}

Screenshots / Logs 📽

2021-07-28T10:59:17.174Z [INFO]: Starting SSR Build...
2021-07-28T11:00:22.834Z [ERROR]: Error: Command failed with exit code 1: node_modules/.bin/next build
                                  Failed to compile.
                                  ModuleNotFoundError: Module not found: Error: Can't resolve 'mongodb' in '/codebuild/.../node_modules/typeorm/platform'
                                  > Build error occurred
                                  Error: > Build failed because of webpack errors

Environment 🖥

System: OS: macOS 11.2.1 CPU: (8) x64 Apple M1 Memory: 21.89 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 14.15.4 - ~/.nvm/versions/node/v14.15.4/bin/node Yarn: 1.22.10 - /opt/homebrew/bin/yarn npm: 7.6.3 - ~/.nvm/versions/node/v14.15.4/bin/npm Watchman: 2021.06.07.00 - /opt/homebrew/bin/watchman Browsers: Chrome: 92.0.4515.107 Safari: 14.0.3 npmPackages: next: 11.0.1 => 11.0.1 next-auth: ^3.27.3 => 3.27.3 react: 17.0.2 => 17.0.2

Contributing 🙌🏽

No, I am afraid I cannot help regarding this

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
IgorDePaulacommented, Jul 30, 2021

I got this error, I fix setting webpack5: false on next.config.js.

2reactions
balazsorban44commented, Sep 6, 2021

So then we can close this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Crash on AWS Amplify build: "Building SSR... can't find ...
Hi! When building my project on AWS Amplify, the build crashes with complaints for missing mongodb in typeorm . Build logs are below....
Read more >
AWS-Amplify/Lobby - Gitter
Hi. I am using Amplify Authenticator Component in an Angular app. The authenticator doesn't detect that my browser language preference is german. Everything...
Read more >
Unable to Deploy Next Js SSR app on AWS amplify. ...
Hi, I'm using next version 10.2.0, so I'm trying to deploy by aws amplify. But I got the error Deploying build artifacts to...
Read more >
Can you host a React site with a database in AWS? : r/reactjs
Only thing I find problematic about amplify is it poor documentation when it comes to deploying next.js with SSR. There are two environment ......
Read more >
Remix Notification
We then make a database query using the AWS Appsync API to retrieve data. This video does not walkthrough setting up an aws...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found