最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Module not found: Error: Can't resolve React-js? - Stack Overflow

programmeradmin7浏览0评论

Module not found: Error: Can't resolve React-js?

ERROR in multi .src/index.js Module not found: Error: Can't resolve '.src/index.js' in 'G:\new-react\reactquiz' @ multi .src/index.js main[0]

ERROR in multi (webpack)-dev-server/client?http://localhost:8080 .src/index.js Module not found: Error: Can't resolve '.src/index.js' in 'G:\new-react\reactquiz' @ multi (webpack)-dev-server/client?http://localhost:8080 .src/index.js main[1] i 「wdm」: Failed to pile.

webpack.config.js

module.exports = {
    entry: [
        '.src/index.js'
    ],
    output:{
        path: __dirname,
        filename: 'app/js/main.js'
    },
    module:{
        rules: [
          { test: /\.css$/, use: 'css-loader' },
          { test: /\.ts$/, use: 'ts-loader' }
        ]
    }
}

index.js

import React from 'react';
import ReactDOM from 'react-dom';
import App from './ponents/App.jsx';

ReactDOM.render(
    <App />,
    document.getElementById('app')
);

App.js

import React, {Component} from 'react';
import ReactDOM from 'react-dom';

class App extends Component{
    render(){
        return(
            <div>
                APP
            </div>
        )
    }
}

export default App

Module not found: Error: Can't resolve React-js?

ERROR in multi .src/index.js Module not found: Error: Can't resolve '.src/index.js' in 'G:\new-react\reactquiz' @ multi .src/index.js main[0]

ERROR in multi (webpack)-dev-server/client?http://localhost:8080 .src/index.js Module not found: Error: Can't resolve '.src/index.js' in 'G:\new-react\reactquiz' @ multi (webpack)-dev-server/client?http://localhost:8080 .src/index.js main[1] i 「wdm」: Failed to pile.

webpack.config.js

module.exports = {
    entry: [
        '.src/index.js'
    ],
    output:{
        path: __dirname,
        filename: 'app/js/main.js'
    },
    module:{
        rules: [
          { test: /\.css$/, use: 'css-loader' },
          { test: /\.ts$/, use: 'ts-loader' }
        ]
    }
}

index.js

import React from 'react';
import ReactDOM from 'react-dom';
import App from './ponents/App.jsx';

ReactDOM.render(
    <App />,
    document.getElementById('app')
);

App.js

import React, {Component} from 'react';
import ReactDOM from 'react-dom';

class App extends Component{
    render(){
        return(
            <div>
                APP
            </div>
        )
    }
}

export default App
Share Improve this question asked Jul 26, 2020 at 10:49 puspus 1011 gold badge2 silver badges9 bronze badges 3
  • 2 It helps to actually read the error message. You wrote .src where I think you meant ./src or simply src. – Thomas Commented Jul 26, 2020 at 10:55
  • ERROR in ./src/index.js 6:4 Module parse failed: Unexpected token (6:4) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See webpack.js/concepts#loaders – pus Commented Jul 27, 2020 at 2:12
  • | ReactDOM.render( > <App />, | document.getElementById('app') | ); @ multi ./src/index.js main[0] i 「wdm」: Failed to pile. – pus Commented Jul 27, 2020 at 2:15
Add a ment  | 

2 Answers 2

Reset to default 2

You'll have to mention the right path for your src folder. ../src or whatever your path is

Check below config

module.exports = {
    entry: [
        './src/index.js'
    ],
    output:{
        path: __dirname,
        filename: 'app/js/main.js'
    },
    module:{
        rules: [
          { test: /\.css$/, use: 'css-loader' },
          { test: /\.ts$/, use: 'ts-loader' }
        ]
    }
}
发布评论

评论列表(0)

  1. 暂无评论