我正在制作nodejs + expressjs服务器和反应胖客户端(SPA)。安装此package.json
后:
{
"name": "express-react",
"version": "1.0.0",
"description": "Some basic ReactJS",
"author": "Greg",
"license": "ISC",
"private": true,
"keywords": [
"reactjs",
"webpack"
],
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.18.2",
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"express": "~4.15.5",
"morgan": "~1.9.0",
"pug": "^2.0.0-rc.4",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-redux": "^5.0.6",
"redux": "^3.7.2",
"redux-logger": "^3.0.6",
"serve-favicon": "~2.4.5"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-react-html-attrs": "^2.1.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"webpack": "^3.10.0",
"webpack-dev-middleware": "^2.0.5"
}
}
运行DEBUG=express-react:* & npm start
命令时出现此错误:
Error: Cannot find module 'webpack-dev-middleware'
我的app.js是由快速生成器生成的:
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var config = require('./webpack.config.js');
const webpackmiddleware = require('webpack-dev-middleware');
var webpack = require('webpack');
const compiler = webpack(config);
var index = require('./routes/index');
var users = require('./routes/users');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(webpackmiddleware(compiler, {
noInfo: true,
publicPath: config.output.publicPath,
stats: {colors: true},
}));
.....
它让我感到困惑..我在package.json文件中定义了webpack-dev-middleware
包,但它说没找到它..为什么?
有没有人遇到过这个问题?
提前感谢您的回复/建议!
答案 0 :(得分:2)
webpack-dev-middleware
中提到了{p> devDependencies
,而不是dependencies
。
如果NODE_ENV
设置为production
,则npm install
仅安装生产依赖项并排除开发依赖项:
要安装devDependencies
,请运行:
npm install --dev