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)
+ 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
:.babelrc
:and at the very top of
_app.js
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 bugOdd 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:
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.
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-753884085https://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 withnext 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.