The create-react-app imports restriction outside of src directory

前端 未结 17 1800
时光说笑
时光说笑 2020-11-22 13:20

I am using create-react-app. I am trying to call an image from my public folder from a file inside my src/components. I am receiving this error message.

17条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 13:47

    You don't need to eject, you can modify the react-scripts config with the rescripts library

    This would work then:

    module.exports = config => {
      const scopePluginIndex = config.resolve.plugins.findIndex(
        ({ constructor }) => constructor && constructor.name === "ModuleScopePlugin"
      );
    
      config.resolve.plugins.splice(scopePluginIndex, 1);
    
      return config;
    };
    

提交回复
热议问题