【问题标题】:Webpack Entry module not found (by tutorial)未找到 Webpack 入口模块(按教程)
【发布时间】:2017-12-31 09:33:08
【问题描述】:

在 codeacademy 找到 this tutorial(链接到最后一页),决定尝试这种部署和配置 js 应用程序的现代方式(决定尝试 ReactJS

一步一步地实现它,就像它被告知的那样,但我遇到了这个错误(当我尝试构建所有东西时)

找不到入口模块中的错误:错误:无法解决 'C:\Users\temp1\Documents\Learn\ReactJS\playaroundapp\index.html' 在 'C:\Users\temp1\Documents\Learn\ReactJS\playaround' 解决 'C:\Users\temp1\Documents\Learn\ReactJS\playaroundapp\index.html' 在 'C:\Users\temp1\Documents\Learn\ReactJS\playaround' 使用描述文件:C:\Users\temp1\Documents\Learn\ReactJS\playaround\package.json (相对路径:.) 字段“浏览器”不包含有效的别名配置 使用描述文件后:C:\Users\temp1\Documents\Learn\ReactJS\playaround\package.json (相对路径:.) 未找到描述文件 没有扩展 字段“浏览器”不包含有效的别名配置 C:\Users\temp1\Documents\Learn\ReactJS\playaroundapp\index.html 不存在 .js 字段“浏览器”不包含有效的别名配置 C:\Users\temp1\Documents\Learn\ReactJS\playaroundapp\index.html.js 不存在 .json 字段“浏览器”不包含有效的别名配置 C:\Users\temp1\Documents\Learn\ReactJS\playaroundapp\index.html.json 不存在 作为目录 C:\Users\temp1\Documents\Learn\ReactJS\playaroundapp\index.html 不存在

我的webpack.config.js:

/** webpack required stuff */
var HTMLWebpackPlugin = require('html-webpack-plugin');

var HTMLWebpackPluginConfig = new HTMLWebpackPlugin({
        template: __dirname + 'app/index.html',
        filename: 'index.html',
        inject: 'body',
        minify: {
            removeComments: true,
            collapseWhitespace: true,
            removeAttributeQuotes: true
        },
        chunksSortMode: 'dependency'
    });

/** thing which traces stuff and transforms in teh better way with babel(?) */
module.exports = {
    entry: __dirname + '/app/index.js',
    module:{
        loaders:[
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: 'babel-loader'
            }
        ]
    },
    output:{
        filename: 'transformed.js',
        path: __dirname + '/build'
    },
    stats: {
            colors: true,
            modules: true,
            reasons: true,
            errorDetails: true
    },
    plugins: [HTMLWebpackPluginConfig]     
};

还有package.json:

{
  "name": "playaround",
  "version": "1.0.0",
  "description": "just test prj",
  "main": "index.js",
  "scripts": {
    "build": "webpack",
    "start": "webpack-dev-server"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "react": "^15.6.1",
    "react-dom": "^15.6.1"
  },
  "devDependencies": {
    "babel-core": "^6.25.0",
    "babel-loader": "^7.1.1",
    "babel-preset-react": "^6.24.1",
    "html-webpack-plugin": "^2.29.0",
    "webpack": "^3.3.0",
    "webpack-dev-server": "^2.6.1"
  }
}

我不知道这里出了什么问题。怎么会?

【问题讨论】:

    标签: reactjs webpack-dev-server


    【解决方案1】:

    路径连接好像少了一个斜线,试试

    var HTMLWebpackPluginConfig = new HTMLWebpackPlugin({
            template: __dirname + '/app/index.html',
    ...
    

    不过,可能更好的方法是使用 path 实用程序模块 (https://nodejs.org/api/path.html),如下所示:

    const path = require('path')
    ...
    template: path.join(__dirname, 'app', 'index.html')
    ...
    

    这使得路径连接更不容易出错并且独立于操作系统(windows 上的反斜杠 vs 斜杠 vs 基于 *nix 的操作系统)

    【讨论】:

    • 哦,没抓到那个,傻我^^非常感谢马特!斜线就是这样!
    猜你喜欢
    • 1970-01-01
    • 2019-01-15
    • 2020-11-16
    • 2017-04-09
    • 2017-07-25
    • 2017-07-23
    • 2021-02-13
    • 2020-05-27
    • 1970-01-01
    相关资源
    最近更新 更多