Module not found: Error: Can't resolve 'net' in 'node_modules/stompjs/lib'

solved it with the following command:

 npm i net -S

To avoid installing random packages, you could add this into your Webpack configuration.

node: {
  net: 'empty',
},

The issue is caused by expecting the net package which is a package from Node.JS and does not exist in the browser.

If you want more information and explanations you can find it here.


To expand a bit on Arthur Costa answer, if you're using NextJS, you can add a configuration in your configuration file to prevent this issue for specific imports.

Add those lines in a file named next.config.js in your root project folder:

module.exports = {
    webpack: (config, { isServer }) => {
        if (!isServer) {
            config.node = {
                net: 'empty'
            };
        }

        return config;
    }
}

In case the problem appears with other built-in modules, you can add those alongside net too.

Source: https://github.com/vercel/next.js/issues/7755#issuecomment-508633125