如何解决在节点js中找不到模块

时间:2018-03-02 10:08:39

标签: javascript node.js

我在桌面上有我的项目。我已删除node_modules文件夹并重新安装它。但它没有用。请帮我解决一下。我已经尝试过堆栈溢出的其他方法,但它们不适合我,我不知道什么是错的。请为我的最终项目提供帮助。 我的文件夹设置:

...
import { getNew } from 'front/actions/NewsActions';

class News extends React.Component {

  componentDidMount() {
    this.props.getNews();
  }

  render() { ... }
}

const mapStateToProps = state => {
  return {
    news: state.News.getIn(['news']),
  };
};

export default connect(mapStateTopProps, {
  getNews,
})(News);

Ols
   +--app.js
   +--package.json
   +--package-lock.json
   +--views
            +--allejs
   +--public
            +--cs
            +---images
   +node_modules

var express = require("express");
var app = express();
var bodyParser = require("body-parser");
app.use(express.static("public"));
mongoose.connect("mongodb://localhost/ols");
app.use(bodyParser.urlencoded({extended: true}));
app.set("view engine", "ejs");


app.get("/", function(req, res) {
	res.render("ols");
});
app.get("/home", function(req, res) {
	res.render("ols");
});
app.get("/alLlaptops", function(req, res) {
	res.render("allLaptops");
});
app.get("/contact", function(req, res) {
	res.render("contact");
});
app.get("/signup", function(req, res) {
	res.render("signup");
});
app.get("/login", function(req, res) {
	res.render("login");
});
app.get("/addtocart", function(req, res) {
	res.render("addtocart");
});


app.listen(3000, function() {
	console.log("Server is listening!!!");
});

1 个答案:

答案 0 :(得分:0)

检查您的package.json文件。您的app.jspackage.json似乎不在同一个文件夹中。

{
  "name": "final-project",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "start": "node app.js" // <--- node can't find app.js file
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

您必须将其更改为:

"scripts": {
    "start": "./views/app.js" // or wherever app.js file is
}