NextJS error on launch: Module not found: Can't resolve 'net'

See original GitHub issue

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/nextjs

SDK Version

7.26.0

Framework Version

13.0.6

Link to Sentry event

No response

Steps to Reproduce

Update from ^7.21.1 to ^7.26.0 leads to an initialization error I did not have before.

I already have a webpack configuration which tell that NodeJS dependencies must not be resolved :

webpack: (config, { isServer }) => {
    if (!isServer) {
      config.resolve = {
        ...config.resolve,
        fallback: {
          // fixes proxy-agent dependencies
          net: false,
          dns: false,
          tls: false,
          assert: false,
          // fixes sentry dependencies
          process: false
        }
      };
    }
    return config;
  },
  sentry: {
    hideSourceMaps: true
  }

I cannot tell why this is happening.

Expected Result

Have no error on next command

Actual Result

error - ./node_modules/https-proxy-agent/dist/agent.js:15:0 Module not found: Can’t resolve ‘net’

Import trace for requested module: ./node_modules/https-proxy-agent/dist/index.js ./src/services/xx/xx.ts ./src/utils/xx/xx.ts ./src/utils/xx/xx.ts ./src/utils/xx/xx/Error.ts ./src/pages/_error.tsx

https://nextjs.org/docs/messages/module-not-found

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
lforstcommented, Dec 16, 2022

I suggest looking at this thread where I go into a bit more detail: https://github.com/getsentry/sentry-javascript/issues/6339

TLDR: Plugins may return functions and you need to pass all args from the module.exports function to it OR you put the sentry plugin last like the docs suggest.

1reaction
azukencommented, Dec 16, 2022

Finally works ! 😃 Thank you for the advice.

Can you please explain a little more what and why you modified ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Can't resolve 'net' in 'node_modules/stompjs/lib' - ...
The issue is caused by expecting the net package which is a package from Node.JS and does not exist in the browser. If...
Read more >
module-not-found
The module you're trying to import is not installed in your dependencies · The module you're trying to import is in a different...
Read more >
How To Solve Module Not Found Can't Resolve 'fs' in Next.js
This error seems straightforward: the filesystem module is not found. Maybe it was not installed or something like that. However, what made this ......
Read more >
How to fix the `can't resolve module` error in Next.js
How to fix the `can't resolve module` error in Next.js ... In a Next.js page your can import methods from a file that...
Read more >
next js module not found: can't resolve 'fs'
As shown in the resolve.fallback section of the Webpack documentation, the primary reason for this config option is because as-of Webpack v5.x, core...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found