next-auth: Module not found: Can't resolve

Your question

Are typeorm warnings during build time caused by next-auth?

What are you trying to do I’m getting the following warnings when I try to build my nextjs project. I used postgres connection for db connection.

./node_modules/typeorm/connection/ConnectionOptionsReader.js
Critical dependency: the request of a dependency is an expression

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve '@sap/hana-client' in '/usr/src/app/node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'better-sqlite3' in '/usr/src/app/node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'hdb-pool' in '/usr/src/app/node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'ioredis' in '/usr/src/app/node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'mongodb' in '/usr/src/app/node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'mssql' in '/usr/src/app/node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'mysql' in '/usr/src/app/node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'mysql2' in '/usr/src/app/node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'oracledb' in '/usr/src/app/node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'pg-query-stream' in '/usr/src/app/node_modules/typeorm/platform'

./node_modules/typeorm/driver/react-native/ReactNativeDriver.js
Module not found: Can't resolve 'react-native-sqlite-storage' in '/usr/src/app/node_modules/typeorm/driver/react-native'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'react-native-sqlite-storage' in '/usr/src/app/node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'redis' in '/usr/src/app/node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'sql.js' in '/usr/src/app/node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'sqlite3' in '/usr/src/app/node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'typeorm-aurora-data-api-driver' in '/usr/src/app/node_modules/typeorm/platform'

Reproduction

Feedback Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.

  • Found the documentation helpful
  • Found documentation but was incomplete
  • Could not find relevant documentation
  • Found the example project helpful
  • Did not find the example project helpful

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 13
  • Comments: 23 (9 by maintainers)

Most upvoted comments

+ to the issue

Since NextJs 11 has moved to webpack 5, NextAuth became absolutely unusable: It simply doesn’t allow to build the project without resolving all of these database packages

I had the same issue and found this thread.

Using next-auth@4.0.0-next.6 (or any next version) got rid of webpack errors, but threw a runtime error 'regeneratorRuntime not found`

And after a lot of research and a lot of failures I ended up making it work like this:

dependencies in package.json:

"dependencies": {
    "core-js": "2",
    "next": "10.2.0",
    "next-auth": "4.0.0-next.6",
    "regenerator-runtime": "^0.13.7"
  },

.babelrc:

{
  "presets": [
    [
      "next/babel",
      {
        "preset-env": {
          // https://github.com/zloirock/core-js#babelpreset-env
          "useBuiltIns": "entry",
          // specifying 3.11 (latest as of writing this) breaks regeneratorRuntime imports, somehow
          "corejs": "2"
        }
      }
    ]
  ]
}

and at the very top of _app.js

import 'core-js';
import 'regenerator-runtime/runtime';

That allowed me to use next/auth in JWT mode (just using the Google Provider) imported as: import GoogleProvider from "next-auth/providers/google" while getting rid of the module not found errors and regeneratorRuntime bug

Odd that it only works with core-js@2 and not with the new core-js@3 versions. But that might be an issue with another dependency.

I hope this helps!

Edit: API routes need the imports as well, as they are standalone functions. Been trying to figure out how to do this a bit more elegantly, but it works for now. Odd that it needs core-js@2, trying to figure out what stops us from using @3.x as it wasn’t the funky dependency I thought it was.

Some observations:

  1. I’m unable to reproduce this issue from next-auth-example repo. Unfortunately I can’t share my actual codebase.
  2. I switched to using Prisma adapter instead of passing DATABASE_URL and the issue still remains.
  3. The issue happens on nextjs 9 and 10.
  4. I deleted the yarn.lock, node_modules and tried to rebuild, but the warning still exists.
  5. The build fails if webpack5 is enabled in nextjs 10.

p.s: I found this PR https://github.com/nextauthjs/next-auth/pull/1682 which avoids importing typeorm by default. I’ll wait for it to be merged. Apologies for the delayed response.

edit: lol I just realised you are the one who is working on the said PR. Awesome @balazsorban44

@s-kris I’m still having this problem, and I’m not using target: "serverless" in my next.config. I looked at the demo page above but it doesn’t have a custom config. Any help would be greatly appreciated!

Having anything at all in the next.config.js makes this error:

`Failed to compile.

ModuleNotFoundError: Module not found: Error: Can’t resolve ‘react-native-sqlite-storage’ in ‘/Users/adamdarby/nextjs/nerd-trivia-redux/node_modules/typeorm/browser/driver/react-native’`

I’m using Next 11.

const FilterWarningsPlugin = require('webpack-filter-warnings-plugin');

module.exports = {
  webpack: (config, { isServer }) => {
    if (!isServer) config.resolve.fallback.fs = false;
    return config;
  },
  eslint: {
    // Warning: Dangerously allow production builds to successfully complete even if
    // your project has ESLint errors.
    ignoreDuringBuilds: true,
  },
  plugins: [
    new FilterWarningsPlugin({
      exclude: [/react-native-sqlite-storage/]
    })
  ]
};

Thanks @balazsorban44 for clearing this up.

Looks like the target: "serverless" is no longer relevant. Those warnings are gone after removing it. Here is the explanation by co-author of nextjs: https://github.com/vercel/next.js/issues/20487#issuecomment-753884085

https://github.com/vercel/next.js/issues/20487#issuecomment-753884085

https://github.com/vercel/next.js/issues/20790#issuecomment-755178273

The Next.js team generally doesn’t recommend using target: "serverless" anymore, especially when using it with next start.

So I am not sure there is anything for us to do here: 🤷

I checked the reproduction here https://github.com/nextauthjs/next-auth/issues/988#issuecomment-821941582 and simply removing target: "serverless" removes the warnings.

So if OP @s-kris approves this as a workaround, I’ll close this issue.

@TeosVerdi it looks like the target declared in your next config cannot be serverless. I’m not 100% on what it means to change that config unfortunately, but it does allow for build.

When it’s merged, I would appreciate feedback either here (encourage you to tag me) on the PR, or in a new issue/discussion. I really hope that #1682 will be as impactful as I think it will be.