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

Next 13: appDir breaks with-mongodb-app example #42277

Closed
1 task done
muslax opened this issue Nov 1, 2022 · 4 comments
Closed
1 task done

Next 13: appDir breaks with-mongodb-app example #42277

muslax opened this issue Nov 1, 2022 · 4 comments
Labels
examples Issue/PR related to examples

Comments

@muslax
Copy link
Contributor

muslax commented Nov 1, 2022

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 21.6.0: Mon Aug 22 20:20:05 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T8101
Binaries:
Node: 16.13.0
npm: 8.19.2
Yarn: 1.22.15
pnpm: 6.11.0
Relevant packages:
next: 13.0.1
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0

Which example does this report relate to?

with-mongodb-app

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

I created next.config.js and set experimental: { appDir: true }, then created app folder with layout.tsx and page.tsx and renamed index.tsx in pages folder to avoid conflict. Here is what inside the page:

import clientPromise from "../lib/mongodb";

async function getData() {
  const client = await clientPromise;
  const db = client.db(process.env.DATABASE_NAME);
  const data = await db.collection("users").find().toArray();
  return data;
}

export default async function Home() {
  const data = await getData();

  return (
    <>
      <h1>Home</h1>
      {data && <pre>Data: {JSON.stringify(data, null, 2)}</pre>}
    </>
  );
}

The getData() manages to load the data, but it always produces long warning in console:

event - compiled client and server successfully in 364 ms (199 modules)
wait  - compiling /page (client and server)...
warn  - ./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
Module not found: Can't resolve 'aws-crt' in '/Users/polt/tmp/with-mongodb-app/node_modules/@aws-sdk/util-user-agent-node/dist-cjs'

./node_modules/mongodb/lib/bson.js
Module not found: Can't resolve 'bson-ext' in '/Users/polt/tmp/with-mongodb-app/node_modules/mongodb/lib'

./node_modules/mongodb/lib/deps.js
Module not found: Can't resolve 'kerberos' in '/Users/polt/tmp/with-mongodb-app/node_modules/mongodb/lib'

./node_modules/mongodb/lib/deps.js
Module not found: Can't resolve '@mongodb-js/zstd' in '/Users/polt/tmp/with-mongodb-app/node_modules/mongodb/lib'

./node_modules/mongodb/lib/deps.js
Module not found: Can't resolve 'snappy' in '/Users/polt/tmp/with-mongodb-app/node_modules/mongodb/lib'

./node_modules/mongodb/lib/deps.js
Module not found: Can't resolve 'snappy/package.json' in '/Users/polt/tmp/with-mongodb-app/node_modules/mongodb/lib'

./node_modules/mongodb/lib/deps.js
Module not found: Can't resolve 'aws4' in '/Users/polt/tmp/with-mongodb-app/node_modules/mongodb/lib'

./node_modules/mongodb/lib/utils.js
Critical dependency: the request of a dependency is an expression

./node_modules/mongodb/lib/utils.js
Module not found: Can't resolve 'mongodb-client-encryption' in '/Users/polt/tmp/with-mongodb-app/node_modules/mongodb/lib'
wait  - compiling...
warn  - ./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
Module not found: Can't resolve 'aws-crt' in '/Users/polt/tmp/with-mongodb-app/node_modules/@aws-sdk/util-user-agent-node/dist-cjs'

./node_modules/mongodb/lib/bson.js
Module not found: Can't resolve 'bson-ext' in '/Users/polt/tmp/with-mongodb-app/node_modules/mongodb/lib'

./node_modules/mongodb/lib/deps.js
Module not found: Can't resolve 'kerberos' in '/Users/polt/tmp/with-mongodb-app/node_modules/mongodb/lib'

./node_modules/mongodb/lib/deps.js
Module not found: Can't resolve '@mongodb-js/zstd' in '/Users/polt/tmp/with-mongodb-app/node_modules/mongodb/lib'

./node_modules/mongodb/lib/deps.js
Module not found: Can't resolve 'snappy' in '/Users/polt/tmp/with-mongodb-app/node_modules/mongodb/lib'

./node_modules/mongodb/lib/deps.js
Module not found: Can't resolve 'snappy/package.json' in '/Users/polt/tmp/with-mongodb-app/node_modules/mongodb/lib'

./node_modules/mongodb/lib/deps.js
Module not found: Can't resolve 'aws4' in '/Users/polt/tmp/with-mongodb-app/node_modules/mongodb/lib'

./node_modules/mongodb/lib/utils.js
Critical dependency: the request of a dependency is an expression

./node_modules/mongodb/lib/utils.js
Module not found: Can't resolve 'mongodb-client-encryption' in '/Users/polt/tmp/with-mongodb-app/node_modules/mongodb/lib'
^C%  

Note: I can build it locally, however when tried to deploy to vercel it failed with near identical error/warning.

Expected Behavior

Should run without error/warning.

To Reproduce

  1. npx create-next-app --example with-mongodb with-mongodb-app
  2. Rename pages/index.tsx to pages/_index.tsx
  3. Create app/layout.tsx and app/page.tsx
  4. npm run dev
  5. npm run build
@muslax muslax added the examples Issue/PR related to examples label Nov 1, 2022
@muslax
Copy link
Contributor Author

muslax commented Nov 1, 2022

I confirm the same behavior also occurs with with-mongodb-mongoose-app example.

@jonasb
Copy link

jonasb commented Nov 1, 2022

I had a similar issue with sqlite3. Have you tried the serverComponentsExternalPackages config?

#41745 (comment)

@ijjk
Copy link
Member

ijjk commented Nov 2, 2022

Hi, this should have been addressed by #42313 which is available in v13.0.2-canary.0 of Next.js, please update and give it a try!

@github-actions
Copy link
Contributor

github-actions bot commented Dec 2, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
examples Issue/PR related to examples
Projects
None yet
Development

No branches or pull requests

3 participants