未找到入口模块:错误:无法解析“./src/index.js" [英] Entry module not found: Error: Can't resolve './src/index.js'

查看:46
本文介绍了未找到入口模块:错误:无法解析“./src/index.js"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在安装一个 React 启动应用程序并添加了 Webpack,但它说 无法解析 './src/index.js'.

I was installing a react startup app and added Webpack, but it says Can't resolve './src/index.js'.

浏览器显示

我的文件路径和 Package.json 内容

Webpack.config.js 内容

 var debug = process.env.NODE_ENV !== "production";
    var webpack = require('webpack');
    var path = require('path');

    module.exports = {
        context: path.join(__dirname, "public"),
    devtool: debug ? "inline-sourcemap" : false,
    entry: "./src/index.js",
    module: {
        loaders: [
            {
                test: /.jsx?$/,
                exclude: /(node_modules|bower_components)/,
                loader: 'babel-loader',
                query: {
                    presets: ['react', 'es2016', 'stage-0'],
                    plugins: ['react-html-attrs', 'transform-decorators-legacy', 'transform-class-properties'],
                }
            }
        ]
    },
    output: {
        path: __dirname + "/public/",
        filename: "build.js"
    },
    plugins: debug ? [] : [
        new webpack.optimize.DedupePlugin(),
        new webpack.optimize.OccurrenceOrderPlugin(),
        new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
    ],
};

推荐答案

你的基本 URL 是 path.join(__dirname, "public"),你的条目是 ./src/index.js.Webpack 尝试在 public 目录中查找 ./src/index.js ;显然它不存在.您应该将 entry 修改为 ../src/index.js.

Your base URL is path.join(__dirname, "public"), and your entry is ./src/index.js. Webpack tries to find ./src/index.js in public dir; obviously it does not exist. You should modify entry to ../src/index.js.

这篇关于未找到入口模块:错误:无法解析“./src/index.js"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆