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

Compiling with Warnings #10633

Closed
samuelcastro opened this issue Feb 21, 2020 · 14 comments
Closed

Compiling with Warnings #10633

samuelcastro opened this issue Feb 21, 2020 · 14 comments
Labels
please add a complete reproduction The issue lacks information for further investigation

Comments

@samuelcastro
Copy link

samuelcastro commented Feb 21, 2020

Bug report

Describe the bug

When building the project locally and on Now I'm getting these warnings:

Compiled with warnings.

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

To Reproduce

1- Have a simple next.js app and try build

Expected behavior

No warnings

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: macOS 10.14.6
  • Version of Next.js: Same issue on 9.2.1 and 9.2.3-canary.8
@samuelcastro samuelcastro changed the title Compiling with Warning Compiling with Warnings Feb 21, 2020
@samuelcastro
Copy link
Author

So I noticed that this only happens with target: serverless.

@timneutkens timneutkens added the please add a complete reproduction The issue lacks information for further investigation label Feb 22, 2020
@timneutkens
Copy link
Member

timneutkens commented Feb 22, 2020

Sounds expected, it means you're importing a library that uses expression requires. Warning can be ignored just fine. eg the dep will have something like this:

require(`./something/from/somewhere/${variable}`)

@timneutkens
Copy link
Member

In the future please add a complete reproduction otherwise it's impossible for us to help you in a way that is productive.

@Tenga
Copy link

Tenga commented Apr 16, 2020

@timneutkens Not sure if this was addressed through some other issue, but if repro steps are needed to reopen this, I can repro this with nothing but the starter template (which pulls [email protected]).

Repro steps:

module.exports = {
  target: 'serverless',
}
  • npm run build

Result is:

Console output

Creating an optimized production build

Compiled with warnings.

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

Automatically optimizing pages

Page                                                           Size     First Load JS
┌ ○ /                                                          6.95 kB          65 kB
└ ○ /404                                                       3.15 kB        61.2 kB
+ First Load JS shared by all                                  58.1 kB
  ├ static/pages/_app.js                                       957 B
  ├ chunks/f55b18d155ba108da95e069adbd66fd30ee008df.82b733.js  10.5 kB
  ├ chunks/framework.0f140d.js                                 40 kB
  ├ runtime/main.235c69.js                                     5.95 kB
  └ runtime/webpack.b65cab.js                                  746 B

λ  (Lambda)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
○  (Static)  automatically rendered as static HTML (uses no initial props)
●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)

✨  Done in 7.42s.

Additional info:

I've been downgrading Next to see if I can see when this started happening, and I've observed that [email protected] seems to be the first version that is showing this issue ([email protected] logging no warnings).


Sounds expected, it means you're importing a library that uses expression requires. Warning can be ignored just fine. eg the dep will have something like this:

require(`./something/from/somewhere/${variable}`)

Unless this is expected from Next itself by default, it does not seem like a user added dependency is causing this, considering it can be reproed with the starter template?

Hopefully it's useful.

@mikestopcontinues
Copy link

Shouldn't this be reopened? I'm experiencing this issue as well.

@jpkempf
Copy link

jpkempf commented May 11, 2020

My impression after reading the comments here is that building Next with target: serverless isn't considered as something most people would want to do. From the docs I gather this happens under the hood for deployments to Vercel and isn't otherwise recommended to do manually. So my guess is these warnings (or fixes for them) might not be high on the list of priorities right now? The actual fix would probably also depend heavily on the specific dependency throwing the warnings, so it wouldn't be a cure-all.

As someone who is looking into the possibility of deploying a Next app to AWS while still profiting from most of the benefits the framework offers, I am mainly interested in whether or not it is safe to ignore these warnings or if something might actually break in certain situations.

@nick-myers-dt
Copy link

We're definitely using Next.js with Serverless, via https://github.com/danielcondemarin/serverless-next.js

@timneutkens
Copy link
Member

As said there is nothing to "fix" here, it's a warning that a certain file could not be bundled as per #10633 (comment). So it was treated as external by webpack.

@Tenga
Copy link

Tenga commented May 11, 2020

@timneutkens Cheers for the reply.

With reference to that comment, I believe the wording of it is what caused the misunderstanding here.

I believe the reason we all continued to comment here is because that comment reads like: "You caused this, because you're doing this"

I understand what the warning is, however, with the above said I assumed you might not be expecting this to happen with a clean installation.

Hopefully we can agree that it's a bit unexpected for Next.js to present you with lengthy warnings you can't get rid of, by flipping the switch to serverless target on a minimal repro case.

Which is why I provided a clean repro and asked:

Unless this is expected from Next itself by default, it does not seem like a user added dependency is causing this, considering it can be reproed with the starter template?

Your reply now, while it doesn't explicitly address if this should be expected or not by default, the only thing I can do is assume in good faith that it is.

Hopefully that clarifies my intent a bit. Apologies for wasting your time.

@mikestopcontinues
Copy link

@timneutkens If the end-user receives a warning, that implies the end-user should fix it. Similarly, if Next expects webpack to treat some files as externals, then Next shouldn't output the warnings. Because the convention is not to warn for expected behavior.

Imagine if npm install output Warning: Files and directories found! Wouldn't you find that concerning?

@timneutkens
Copy link
Member

The serverless target as-is is not ideal in many cases, eg it bundles dependencies that are hard to bundle, hence why we started working on a new target called serverless-trace which does not bundle node_modules anymore and as such does not show this type of warning (as it literally does not bundle the deps that cause it).

Imagine if npm install output Warning: Files and directories found! Wouldn't you find that concerning?

npm is a bad example to make that point given that it shows a ton of non-actionable warnings and messages always.

In this case the warning (shown by webpack) is relaying that it's ignoring a certain file's dynamic require. It's more-so an information message but we currently just output webpack errors and warnings as-is.

@awitherow
Copy link

I am getting this when I created a dynamic function for importing.

import NextDynamic from "next/dynamic";

const dynamic = (path) => NextDynamic(() => import(path));

export default dynamic;

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
please add a complete reproduction The issue lacks information for further investigation
Projects
None yet
Development

No branches or pull requests

9 participants