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

前端 未结 6 1304
夕颜
夕颜 2021-02-18 20:38

Got an issue where a stompJS-lib was not found, upon which I got the following error message:

Module not found: Error: Can\'t resolve \'net\' in \'/../../../.../         


        
6条回答
  •  眼角桃花
    2021-02-18 21:21

    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

提交回复
热议问题