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

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

    install these two packages

    npm i --save-dev react-app-rewired customize-cra
    

    package.json

    "scripts": {
        - "start": "react-scripts start"
        + "start": "react-app-rewired start"
    },
    

    config-overrides.js

    const { removeModuleScopePlugin } = require('customize-cra');
    
    module.exports = function override(config, env) {
        if (!config.plugins) {
            config.plugins = [];
        }
        removeModuleScopePlugin()(config);
    
        return config;
    };
    
    

提交回复
热议问题