javascript - Webpack-dev-server 找不到模块

标签 javascript node.js webpack-dev-server

欢迎,

我尤其是 React 和 Node.js 新手。我想了解一些有关 React 的知识,但最终却在 Node.js 上陷入了困境。问题是我无法正确设置网络开发服务器。很抱歉,如果这个问题看起来很琐碎,尽管我几个小时都没有找到解决方案。

这是: webpack.config.js

module.exports = {
    entry: './src/index.js',
    output: {
        path: __dirname,
        filename: 'app/js/main.js'
    },
    module: {
        loaders: [{
                test: /\.jsx?$/,
                loader: 'babel',
                exclude: /node_modules/
            }]
    }
}

package.json

{
  "name": "Github_profile_viewer",
  "version": "0.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "BSD", 
  "devDependencies": {
    "babel-core": "5.8.*",
    "babel-loader": "5.3.*",
    "webpack": "1.12.*",
    "webpack-dev-server": "1.10.*"
  },
  "dependencies": {
    "react": "^0.14,7",
    "react-dom": "^0.14.7"
  }
}

<强> http://localhost:8080/app/js/main.js

/******/ (function(modules) { // webpackBootstrap
/******/    // The module cache
/******/    var installedModules = {};

/******/    // The require function
/******/    function __webpack_require__(moduleId) {

/******/        // Check if module is in cache
/******/        if(installedModules[moduleId])
/******/            return installedModules[moduleId].exports;

/******/        // Create a new module (and put it into the cache)
/******/        var module = installedModules[moduleId] = {
/******/            exports: {},
/******/            id: moduleId,
/******/            loaded: false
/******/        };

/******/        // Execute the module function
/******/        modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/        // Flag the module as loaded
/******/        module.loaded = true;

/******/        // Return the exports of the module
/******/        return module.exports;
/******/    }


/******/    // expose the modules object (__webpack_modules__)
/******/    __webpack_require__.m = modules;

/******/    // expose the module cache
/******/    __webpack_require__.c = installedModules;

/******/    // __webpack_public_path__
/******/    __webpack_require__.p = "";

/******/    // Load entry module and return exports
/******/    return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

    (function webpackMissingModule() { throw new Error("Cannot find module \"./src/index.js\""); }());


/***/ }
/******/ ]);

当我尝试建立 webpack-dev-server 时,我也收到这样的警告: CMD Error

唉,我已经 npm 安装了所需的模块(至少应该是这样)。

我不知道我必须做什么才能让它发挥作用:(

最佳答案

这是一个缓存错误或类似的错误。一个快速的解决方案可能是:

rm -rf node_modules
rm -rf ~/.npm
npm install -g npm
npm install

关于javascript - Webpack-dev-server 找不到模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37737335/

相关文章:

javascript - 如何使用 CSS 和 JavaScript 创建可自定义的动态网格布局?

node.js - 如何在 Firebase Cloud Functions 中捆绑和要求非 JS 依赖项?

node.js - Facebook 营销 API : How to get the optimization event

linux - 终止 webpack-dev-server 后执行 bash

javascript - 我的 Angular Directive(指令)不起作用

javascript - 上传完成后如何获取json结果?

javascript - 如何使用 sails.js 自定义颜色记录器

webpack - 在 webpack-dev-server 上启用 gzip 压缩?

proxy - webpack-dev-server中的代理websockets连接

javascript - 删除?来自 document.location.search