简体   繁体   English

找不到模块:错误:无法解析 React-js?

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

Module not found: Error: Can't resolve React-js?找不到模块:错误:无法解析 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]未找到 multi.src/index.js 模块中的错误:错误:无法解析 'G:\new-react\reactquiz' @ multi.src/index.js main[0] 中的 '.src/index.js'

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 compile.多(webpack)-dev-server/client 中的错误?http://localhost:8080.src/index.js 未找到模块:错误:无法解析 'G:\new 中的 '.src/index.js' -react\reactquiz'@multi (webpack)-dev-server/client?http://localhost:8080.src/index.js main[1] i 「wdm」:编译失败。

webpack.config.js 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 index.js

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

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

App.js应用程序.js

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

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

export default App

You'll have to mention the right path for your src folder.您必须提及 src 文件夹的正确路径。 ../src or whatever your path is ../src或任何你的路径

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' }
        ]
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM