__dirname is not working in node js with webpack bundling

后端 未结 2 1370
孤独总比滥情好
孤独总比滥情好 2021-02-19 21:36

My current directory is

D:\\bkp\\Programming\\TestWorks\\nodejs\\testApp

but when i am using __dirname and trying to show a file

2条回答
  •  渐次进展
    2021-02-19 22:14

    This is because webpack can handle __dirname (and other node specific things) in different ways. If you want it to behave like normal, use this in your webpack config:

    {
        node: {
            __dirname: false
        }
    }
    

    See: https://webpack.js.org/configuration/node/

提交回复
热议问题