Reactjs 未找到[React]模块:您试图导入.././img/photo.jpg,它位于项目src/目录之外。不支持src/src

Reactjs 未找到[React]模块:您试图导入.././img/photo.jpg,它位于项目src/目录之外。不支持src/src,reactjs,Reactjs,我有一个有问题的错误,这是我的项目树 这是我的密码 import React, { Component } from 'react'; import { Grid, Cell } from 'react-mdl'; import img from "../../img/photo.jpg"; class Landing extends Component { render() { return( <div style={{wid

我有一个有问题的错误,这是我的项目树

这是我的密码

    import React, { Component } from 'react'; 
import { Grid, Cell } from 'react-mdl';
import img from "../../img/photo.jpg";

class Landing extends Component {
    render() {
        return(
            <div style={{width: '100%', margin: 'auto'}}>
                <Grid className="landing-grid">
                    <Cell col={12}>
                        <img src={img} alt="logo"/>
                    </Cell>
                </Grid>

            </div>
        )
    }
}

export default Landing; 
import React,{Component}来自'React';
从'react mdl'导入{Grid,Cell};
从“../../img/photo.jpg”导入img;
类扩展组件{
render(){
返回(
)
}
}
导出默认着陆;

图像不显示,您有解决方案吗?谢谢

您不必导入图像等资产。只需将它们放在公用文件夹中,并使用环境变量对其进行寻址。例如:

import React, { Component } from 'react'; 
import { Grid, Cell } from 'react-mdl';

class Landing extends Component {
    render() {
        return(
            <div style={{width: '100%', margin: 'auto'}}>
                <Grid className="landing-grid">
                    <Cell col={12}>
                        return <img src={process.env.PUBLIC_URL + '/img/photo.jpg'} />
                    </Cell>
                </Grid>

            </div>
        )
    }
}

export default Landing; 
import React,{Component}来自'React';
从'react mdl'导入{Grid,Cell};
类扩展组件{
render(){
返回(
返回
)
}
}
导出默认着陆;
注意:可以在名为public的根文件夹中找到
public
文件夹,例如:
YourAppName/public
。所有人都建议在其中创建一个
static
文件夹,并按类型放置所有资产,例如
static/img
,然后您的地址将是
process.env.PUBLIC\u URL+'/static/img/photo.jpg


PS:

您不必导入图像等资产。只需将它们放在公用文件夹中,并使用环境变量对其进行寻址。例如:

import React, { Component } from 'react'; 
import { Grid, Cell } from 'react-mdl';

class Landing extends Component {
    render() {
        return(
            <div style={{width: '100%', margin: 'auto'}}>
                <Grid className="landing-grid">
                    <Cell col={12}>
                        return <img src={process.env.PUBLIC_URL + '/img/photo.jpg'} />
                    </Cell>
                </Grid>

            </div>
        )
    }
}

export default Landing; 
import React,{Component}来自'React';
从'react mdl'导入{Grid,Cell};
类扩展组件{
render(){
返回(
返回
)
}
}
导出默认着陆;
注意:可以在名为public的根文件夹中找到
public
文件夹,例如:
YourAppName/public
。所有人都建议在其中创建一个
static
文件夹,并按类型放置所有资产,例如
static/img
,然后您的地址将是
process.env.PUBLIC\u URL+'/static/img/photo.jpg

PS: