欢迎,
我尤其是 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/