我是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
所需模塊(至少應該是這樣)。
我不知道我必須做的,做它的工作原理:(
什麼是您的應用程序的目錄結構確保EN嘗試點在'。/ src/index.js'中 – zeronone
圖片中的錯誤說明沒有找到lodash。試試'npm install --save lodash' – zeronone
謝謝你的回答,但他們沒有幫助。 1.我不能使用npm install --save lodash,它會導致錯誤。不過,我在package.json文件中添加了lodash作爲依賴和devDependency。當我運行npn安裝它運行,但webpack-dev-server仍然找不到它。 2.我的文件結構確實很好:( – 0blivion6