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

@nrwl/next: Cannot find module '@nrwl/next/plugins/with-nx' #15931

Closed
1 of 4 tasks
grz-gajda opened this issue Mar 28, 2023 · 4 comments · Fixed by #16469
Closed
1 of 4 tasks

@nrwl/next: Cannot find module '@nrwl/next/plugins/with-nx' #15931

grz-gajda opened this issue Mar 28, 2023 · 4 comments · Fixed by #16469
Assignees
Labels
outdated scope: nextjs Issues related to NextJS support for Nx type: docs

Comments

@grz-gajda
Copy link

grz-gajda commented Mar 28, 2023

Documentation issue

  • Reporting a typo
  • Reporting a documentation bug
  • Documentation improvement
  • Documentation feedback

Is there a specific documentation page you are reporting?

@nrwl/next -> Setting up Next.js

Additional context or description

With changes from #15824 package @nrwl/next needs to be included in dependencies, not in the devDependencies, otherwise generated package.json doesn't have @nrwl/next and it's not possible to run the Next's application because of error:

error - Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error
Error: Cannot find module '@nrwl/next/plugins/with-nx'

Workspace generated by command npx create-nx-workspace@latest --preset=next have @nrwl/next in the dependencies.

@AgentEnder AgentEnder added the scope: nextjs Issues related to NextJS support for Nx label Mar 30, 2023
@MateuszGroth
Copy link

Is it actually a good idea to require @nrwl/next as a dependency? When I run the built project on a lean nodejs image, installing this causes an error due to lack of required libs to compile the module. Previously the imported 'with-nx' plugin was transpiled during the build time.

image

@grz-gajda
Copy link
Author

Is it actually a good idea to require @nrwl/next as a dependency?

Not only @nrwl/next is required as dependency but also all of plugins imported in next.config.js. I've been using next-translate and I had to move next-translate-plugin from devDependencies to dependencies. For sure it's breaking change but I don't have an opinion which way is better (like it's right now or how it was previous), that's why I made an issue for documentation.

@jaysoo
Copy link
Member

jaysoo commented Apr 21, 2023

I think there are two separate issues here.

  1. Some Next.js plugins like next-translate are actually needed during production runtime. So you do need to have them installed for production. This is because the compiled runtime code will need to import things like next-translate/appWithI18n.
  2. Currently @nrwl/next is also needed for production to run, but it is pulling in other modules that aren't needed.

(1) is not an Nx issue. If you know a plugin isn't needed you must check for the phase in your next.config.js file. Such as:

const { PHASE_PRODUCTION_SERVER } =require('next/constants');

const nextConfig = {
  reactStrictMode: true,
};

module.exports = (phase) => {
  if (phase === PHASE_PRODUCTION_SERVER) {
    return nextConfig;
  } else  {
    // This plugin only has an effect during build (e.g. it applies additional transforms)
    const somePlugin = require('some-dev-only-plugin');
    return somePlugin(nextConfig);
  }
}

(2) is something we can address for Nx 16. For now you must install it as a prod dependency.

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: nextjs Issues related to NextJS support for Nx type: docs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants