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

前端 未结 17 1817
时光说笑
时光说笑 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:43

    The package react-app-rewired can be used to remove the plugin. This way you do not have to eject.

    Follow the steps on the npm package page (install the package and flip the calls in the package.json file) and use a config-overrides.js file similar to this one:

    const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
    
    module.exports = function override(config, env) {
        config.resolve.plugins = config.resolve.plugins.filter(plugin => !(plugin instanceof ModuleScopePlugin));
    
        return config;
    };
    

    This will remove the ModuleScopePlugin from the used WebPack plugins, but leave the rest as it was and removes the necessity to eject.

提交回复
热议问题