Webpack错误读取/解析入口模块

时间:2018-12-23 06:03:09

标签: npm webpack module

尝试在webpack上执行监视命令时收到错误,无法解决问题。我有一个以上的问题,但我可以肯定,我至少对其中一个问题有所了解。

为了提供一些背景知识,我不了解所有这些知识,而是试图自学如何用python编写Web应用程序。我偶然发现了此博客文章,并提供了一个带有详细说明的基本示例:

https://codeburst.io/creating-a-full-stack-web-application-with-python-npm-webpack-and-react-8925800503d9

...,并且从源材料获取没有上下文的错误。他们还展示了githubyoutube视频,但仍然没有运气。

我认为问题的部分原因是他们的示例是在MAC上编写的,该目录的工作方式与我的计算机Windows略有不同,因此在该代码的一部分中,该目录似乎已关闭。这是显示Node.js,文件夹和webpack.config.js代码的屏幕截图:

Here's a screenshot showing the Node.js, the file folder, and the webpack.config.js code:

我注意到示例中的目录具有'/static/js/index.jsx',但是我的目录使用了另一个斜杠\ static \ js \ index.jsx,并且错误将奇数组合显示为C:\用户... \ static / static / js / index.jsx。得知\是JavaScript中的转义代码后,我最终尝试使用更改的斜杠重新执行该代码。

Here's another screenshot showing the newly run effect ... and it didn't appear to have an effect.

所以我不确定我“修复”的内容是否也是一个错误,但不是当前错误,因为对于我来说,目录斜杠如何更改是没有意义的……但仍然没有真正的答案和我的知识太薄了,无法有效查找或了解问题的性质。

我觉得实际的模块在webpack代码中可能是或者可能还有某种错误,但是我不太确定。

感谢您一直以来对我的帮助, 马特

编辑:原始帖子具有代码的屏幕截图,并引用了它的复制源材料,但是作为参考,以下是代码段:

目录布局为:

| Documents
|--- Python Scripts
    |--- fullstacktemplate
        |---  fullstack_template
            |--- static
                |--- js
                    |--- index.jsx
                | node_modules
                | index.html
                | package.json
                | package-lock.json
                | webpack.config.js

node_modules和package-lock.json是通过设置NPM,Webpack和/或Babel自动创建的。 Package.json被进一步编辑,将在下面列出。

index.jsx是1行:

alert("Hello World!");

package.json如下:

{
  "name": "fullstacktemplate",
  "version": "1.0.0",
  "description": "fullstack template that will say hello in another language when activated",
  "main": "index.jsx",

  "scripts": {
    "build": "webpack -p --progress --config webpack.config.js",
    "dev-build": "webpack --progress -d --config webpack.config.js",
    "test": "echo \"Error: no test specified\" && exit 1",
    "watch": "webpack --progress -d --config webpack.config.js --watch"
    },

  "keywords": [
    "python",
    "react",
    "npm",
    "webpack"
    ],

  "author": "Matt Lane",
  "license": "ISC",

  "devDependencies": {
    "webpack": "^4.28.2"
    }
}

webpack.config.js如下:

const webpack = require('webpack');
const config = {
    entry:  __dirname + '\\js\\index.jsx',
    output: {
        path: __dirname + '\\dist',
        filename: 'bundle.js',
    },
    resolve: {
        extensions: ['.js', '.jsx', '.css']
    },
    module: {
        rules: [
        {
          test: /\.jsx?/,
                exclude: /node_modules/,
                use: 'babel-loader'
          }
        ]
    }
};

module.exports = config;

webpack.config.js文件是我的“更正”文件,带有\斜杠。未经编辑的原始版本是:

const webpack = require('webpack');
const config = {
    entry:  __dirname + '/js/index.jsx',
    output: {
        path: __dirname + '/dist',
        filename: 'bundle.js',
    },
    resolve: {
        extensions: ['.js', '.jsx', '.css']
    },
    module: {
        rules: [
        {
          test: /\.jsx?/,
                exclude: /node_modules/,
                use: 'babel-loader'
          }
        ]
    }
};

module.exports = config;

0 个答案:

没有答案