Can't resolve module (not found) in React.js

前端 未结 15 1408
太阳男子
太阳男子 2020-12-07 22:03

I can\'t believe that I\'m asking an obvious question, but I still get the error in console log.

Console says that it can\'t find the module in the directory, but I\

15条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-07 22:31

    in my case, The error message was

    Module not found: Error: Can't resolve '/components/body
    

    While everything was in the correct directory.

    I found that renaming body.jsx to body.js resolve the issue!

    So I added this code in webpack.config.js to resolve jsx as js

     module.exports = {
      //...
      resolve: {
        extensions: ['.js', '.jsx']
      }
    };
    

    And then build error gone!

提交回复
热议问题