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

Module not found: Can't resolve <name> #988

Closed
5 tasks
s-kris opened this issue Dec 23, 2020 · 24 comments
Closed
5 tasks

Module not found: Can't resolve <name> #988

s-kris opened this issue Dec 23, 2020 · 24 comments
Labels
incomplete Insufficient reproduction. Without more info, we won't take further actions/provide help. question Ask how to do something or how something works upstream The issue dervies from one of next-auth dependencies

Comments

@s-kris
Copy link

s-kris commented Dec 23, 2020

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
@s-kris s-kris added the question Ask how to do something or how something works label Dec 23, 2020
@balazsorban44 balazsorban44 added the incomplete Insufficient reproduction. Without more info, we won't take further actions/provide help. label Jan 1, 2021
@balazsorban44
Copy link
Member

Could you please add a reproduction repo with a link to debug this?

@s-kris
Copy link
Author

s-kris commented Apr 13, 2021

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 #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

@balazsorban44
Copy link
Member

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.

@s-kris
Copy link
Author

s-kris commented Apr 17, 2021

@balazsorban44 I used the latest next-auth": "^4.0.0-next.4 package and the following warnings occurred during build time. I'm using typescript btw.

./node_modules/next/dist/next-server/server/load-components.js
Critical dependency: the request of a dependency is an expression

./node_modules/next/dist/next-server/server/load-components.js
Critical dependency: the request of a dependency is an expression

./node_modules/next/dist/next-server/server/require.js
Critical dependency: the request of a dependency is an expression

./node_modules/next/dist/next-server/server/require.js
Critical dependency: the request of a dependency is an expression

./node_modules/next/dist/next-server/server/require.js
Critical dependency: the request of a dependency is an expression

./node_modules/@prisma/client/runtime/index.js
Critical dependency: the request of a dependency is an expression

./node_modules/typeorm/platform/PlatformTools.js
Critical dependency: the request of a dependency is an expression

./node_modules/typeorm/util/DirectoryExportedClassesLoader.js
Critical dependency: the request of a dependency is an expression

./node_modules/typeorm/util/DirectoryExportedClassesLoader.js
Critical dependency: the request of a dependency is an expression

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

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

./node_modules/app-root-path/lib/app-root-path.js
Critical dependency: the request of a dependency is an expression

./node_modules/require_optional/index.js
Critical dependency: the request of a dependency is an expression

./node_modules/require_optional/index.js
Critical dependency: the request of a dependency is an expression

./node_modules/require_optional/index.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 '<path>node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'better-sqlite3' in '<path>node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'hdb-pool' in '<path>node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'ioredis' in '<path>node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'mongodb' in '<path>node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'mssql' in '<path>node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'mysql' in '<path>node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'mysql2' in '<path>node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'oracledb' in '<path>node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'pg-query-stream' in '<path>node_modules/typeorm/platform'

./node_modules/typeorm/driver/react-native/ReactNativeDriver.js
Module not found: Can't resolve 'react-native-sqlite-storage' in '<path>node_modules/typeorm/driver/react-native'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'react-native-sqlite-storage' in '<path>node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'redis' in '<path>node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'sql.js' in '<path>node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'sqlite3' in '<path>node_modules/typeorm/platform'

./node_modules/typeorm/platform/PlatformTools.js
Module not found: Can't resolve 'typeorm-aurora-data-api-driver' in '<path>node_modules/typeorm/platform'

@balazsorban44
Copy link
Member

yes, it unfortunately needs more tinkering. I have ideas, but I don't have an ETA. You can just follow the next branch.

@s-kris
Copy link
Author

s-kris commented Apr 17, 2021

Sure, thank you.

@s-kris
Copy link
Author

s-kris commented Apr 17, 2021

@balazsorban44

Okay. So due to my OCD, I landed on typeorm's docs: https://github.com/typeorm/typeorm/blob/master/docs/faq.md#how-to-use-webpack-for-the-backend
We need to suppress unused drivers and Module not found warnings are gone.

@balazsorban44 balazsorban44 reopened this Apr 17, 2021
@balazsorban44
Copy link
Member

balazsorban44 commented Apr 17, 2021

Is this something we should point users to when they have this issue? To be honest, I think I used the TypeORM adapter only once locally to test something with the Email provider (with Postgres), and I don't remember seeing these warnings. Do you maybe have a reproduction (with the current latest release) that produces these warnings?

@s-kris
Copy link
Author

s-kris commented Apr 18, 2021

Hey @balazsorban44
I think, yes, maybe we can drop a note about typeorm warnings.

But, hey, I successfully reproduced the bug. Phew! It's due to next.config.js. I added next-images module just to showcase that I need to have custom config via next.config.js.

min repo: https://github.com/s-kris/test-next-auth-custom-server-typescript

@jonashaefele
Copy link

jonashaefele commented May 1, 2021

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.

@balazsorban44
Copy link
Member

Be aware that the next branch is very unstable at the moment, I cannot guarantee that it works at any time for now.

I intend to work out how to exclude TypeORM from default bundles with the least amount of break, and I also would like to modernize our bundle output, as (in theory) the lowest version of Node that we should aim for is Node 12. Next.js supports 10.13, but I don't think there is any point for us to go lower than that.

Upgrading out babel output will greatly impact the bundle size and probably performance as well, as much less boilerplate will be needed, since Node12 and up supports async out of the box!

@muhaimincs
Copy link

Did you able to build it?

@bcnichols3
Copy link

bcnichols3 commented Jul 2, 2021

EDIT: Looks like you can no longer target serverless in your next.config while using Next-Auth.

Seeing similar issues when trying to build locally or in CI:

info  - Loaded env from /Users/briangriggs/Git/recipe-book/.env.production.local
info  - Loaded env from /Users/briangriggs/Git/recipe-book/.env.local
info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
info  - Checking validity of types
info  - Creating an optimized production build
Failed to compile.

ModuleNotFoundError: Module not found: Error: Can't resolve 'better-sqlite3' in '/Users/briangriggs/Git/recipe-book/node_modules/@next-auth/typeorm-legacy-adapter/node_modules/typeorm/platform'

> Build error occurred
Error: > Build failed because of webpack errors
    at /Users/briangriggs/Git/recipe-book/node_modules/next/dist/build/index.js:15:924
    at async Span.traceAsyncFn (/Users/briangriggs/Git/recipe-book/node_modules/next/dist/telemetry/trace/trace.js:6:584)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

It looks like without explicit dependency of all the modules @s-kris listed the build will fail — but I've been installing packages for quite some time without any change. It feels like maybe recursive dependencies aren't being pulled, and likely don't need to be pulled, but when webpack hits TypeORM, it thinks it needs them.

Tried falling back to Webpack 4, but no change.

Also tried disconnecting my DB from next auth, no change.

Added to next.config.js file:

config.plugins.push(
      new FilterWarningsPlugin({
        exclude: [
          /mongodb/,
          /mssql/,
          /mysql/,
          /mysql2/,
          /oracledb/,
          /pg-native/,
          /pg-query-stream/,
          /react-native-sqlite-storage/,
          /redis/,
          /sqlite3/,
          /sql.js/,
          /typeorm-aurora-data-api-driver/,
        ],
      })
    );

Note, I'm using postgres, so am keeping pg but an error still occurs that now looks like this:

ModuleNotFoundError: Module not found: Error: Can't resolve 'mongodb' in '/Users/briangriggs/Git/recipe-book/node_modules/typeorm/platform'

Note the issue is now directly with typeorm, and not with @next-auth/typeorm-legacy-adapter/

@TeosVerdi
Copy link

+ 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

@bcnichols3
Copy link

@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.

@balazsorban44
Copy link
Member

balazsorban44 commented Jul 7, 2021

@TeosVerdi we do have a running demo page at https://github.com/nextauthjs/next-auth-example

that runs on Vercel, using Next.js 11, so saying it is absolutely unusable is a bit of an exaggeration. Maybe you could rather provide a reproduction of your problem, so we can have a look together and see what can be done? 🙂 +1 commenting an issue has absolutely no value for us in helping you.

@bcnichols3 you are right, see my comment below!

@balazsorban44
Copy link
Member

balazsorban44 commented Jul 7, 2021

vercel/next.js#20487 (comment)

vercel/next.js#20790 (comment)

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 #988 (comment) and simply removing target: "serverless" removes the warnings.

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

@bcnichols3
Copy link

bcnichols3 commented Jul 7, 2021

@balazsorban44 is there a writeup as to what target: "serverless" does and why users should be removing it? Is it officially deprecated yet or on the road to being deprecated?

I wasn't getting warnings, I was getting full-blown errors so burned some cycles trying to figure out WTH was wrong. For those that come later maybe it'd be great to have some extra explanation here.

@balazsorban44
Copy link
Member

I am not sure of the state, but regardless, it is certainly not a problem of NextAuth.js.

@balazsorban44 balazsorban44 added the upstream The issue dervies from one of next-auth dependencies label Jul 7, 2021
@s-kris
Copy link
Author

s-kris commented Jul 7, 2021

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: vercel/next.js#20487 (comment)

@s-kris s-kris closed this as completed Jul 7, 2021
@kyds3k
Copy link

kyds3k commented Jul 9, 2021

@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/]
    })
  ]
};

@TeosVerdi
Copy link

TeosVerdi commented Jul 10, 2021

@balazsorban44
In my last comment i said next@11 isn't building the project w/NextAuth, sorry for not elaborating any further.
I have no target: 'serverless' in next.config.js configuration, but i still get the build error.
Maybe i'm missing something.

next.config.js

/* eslint-disable @typescript-eslint/no-var-requires */
const { i18n } = require('./next-i18next.config');
// IEKILL
const withTM = require('next-transpile-modules')(['next-auth']);

module.exports = withTM({
  productionBrowserSourceMaps: true,
  i18n,
  webpack(config, options) {
    config.module.rules.push({
      test: /\.svg$/,
      use: ['@svgr/webpack'],
    });
    config.resolve.modules.push(__dirname);

    if (!options.isServer) {
      config.resolve.alias['@sentry/node'] = '@sentry/browser';
      // IEKILL
      config.resolve.alias['react-hook-form'] =
        'react-hook-form/dist/index.ie11';
    }
    return config;
  },
  sassOptions: {
    includePaths: ['src/styles'],
    prependData: `@import "global/variables.scss";`,
  },
});

build error:

info  - Loaded env from C:\brrrrrr\frontend\.env
(node:13456) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
(Use `node --trace-warnings ...` to show where the warning was created)
info  - Checking validity of types  
info  - Creating an optimized production build  
Failed to compile.

ModuleNotFoundError: Module not found: Error: Can't resolve 'hdb-pool' in 'C:\brrrrrr\frontend\.yarn\cache\typeorm-npm-0.2.34-590a97efd6-1bf2488a19.zip\node_modules\typeorm\platform'


> Build error occurred
Error: > Build failed because of webpack errors
    at C:\brrrrrr\frontend\.yarn\$$virtual\next-virtual-f70edc9490\0\cache\next-npm-11.0.1-c40bc7f380-823700a2a0.zip\node_modules\next\dist\build\index.js:15:924
    at async Span.traceAsyncFn (C:\brrrrrr\frontend\.yarn\$$virtual\next-virtual-f70edc9490\0\cache\next-npm-11.0.1-c40bc7f380-823700a2a0.zip\node_modules\next\dist\telemetry\trace\trace.js:6:584)

Asking to reopen the issue, since it's not resolved completely.

@balazsorban44
Copy link
Member

The OP's issue is resolved, so I recommend opening a new bug report with a reproduction. 😊

@jackhefoong
Copy link

Seems like for google, twitter etc it is able to import when using, next-auth/providers/{{package}}
but what about the provider itself? i keep getting this eslint error
Unable to resolve path to module 'next-auth/providers'. when importing

import { Provider } from 'next-auth/providers';

I do not see any module export for next-auth/providers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
incomplete Insufficient reproduction. Without more info, we won't take further actions/provide help. question Ask how to do something or how something works upstream The issue dervies from one of next-auth dependencies
Projects
None yet
Development

No branches or pull requests

8 participants