2016-06-09 103 views
1

欢迎,Webpack-dev-server无法找到模块

我是React和Node.js的新手,特别是。我想学习一些关于React的知识,并最终与Node.js一起挣扎。问题是我无法正确设置Web-dev-server。对不起,如果这个问题似乎trival,虽然我还没有找到一个小时的解决方案。

这就是: 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\""); }()); 


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

我也收到这样的warrning当我尝试建立的WebPack-dev的服务器: CMD Error

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

我不知道我必须做的,做它的工作原理:(

+0

什么是您的应用程序的目录结构确保EN尝试点在'。/ src/index.js'中 – zeronone

+1

图片中的错误说明没有找到lodash。试试'npm install --save lodash' – zeronone

+0

谢谢你的回答,但他们没有帮助。 1.我不能使用npm install --save lodash,它会导致错误。不过,我在package.json文件中添加了lodash作为依赖和devDependency。当我运行npn安装它运行,但webpack-dev-server仍然找不到它。 2.我的文件结构确实很好:( – 0blivion6

回答

1

看来lodash应通过npm install被包括在内,但的WebPack-DEV-服务器无法找到它:

npm install

0

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

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