Webpack-dev-server找不到模块

时间:2016-06-09 22:40:18

标签: javascript node.js webpack-dev-server

欢迎,

我特别喜欢React和Node.js。我想学习一些关于React的东西并最终与Node.js斗争。问题是我无法正确设置web-dev服务器。对不起,如果这个问题看起来很微不足道,虽然我还没有找到解决方案几个小时。

这是: 的 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 installed需要模块(至少它应该是那样)。

我不知道我必须做些什么来使其有效:(

2 个答案:

答案 0 :(得分:1)

似乎应该通过npm install包含lodash,但webpack-dev-server无法找到它:

npm install

答案 1 :(得分:0)

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

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