Angular2 + Express + Mongoose错误TS2307:找不到模块'mongoose'

时间:2016-11-10 09:23:21

标签: node.js express angular typescript mongoose

我正在学习Angular2我开始从Angular2-express-starter编写我的应用程序,但昨天编译器找不到Mongoose模块。

server/shemas/product.ts(4,27): error TS2307: Cannot find module 'mongoose'.

app.ts

import * as express from 'express'; 
import { json, urlencoded } from 'body-parser'; 
import * as path from 'path'; 
import * as cors from 'cors'; 
import * as compression from 'compression';

import { loginRouter } from './routes/login'; 
import { protectedRouter } from './routes/protected'; 
import { publicRouter } from './routes/public'; 
import { feedRouter } from './routes/feed'; 
import {listRouter} from "./routes/list";

const app: express.Application = express();

app.disable('x-powered-by');

app.use(json()); 
app.use(compression()); 
app.use(urlencoded({ extended: true }));

// allow cors only for local dev app.use(cors({   origin: 'http://localhost:4200' }));

// app.set('env', 'production');

//mongodb connection

var mongoose = require('mongoose'); mongoose.connect("mongodb://<my-adress>:27017");

// api routes app.use('/api/secure', protectedRouter); app.use('/api/login', loginRouter); app.use('/api/public', publicRouter); app.use('/api/feed', feedRouter); app.use('/api/list', listRouter);

if (app.get('env') === 'production') {

  // in production mode run application from dist folder   app.use(express.static(path.join(__dirname, '/../client'))); }

// catch 404 and forward to error handler app.use(function(req: express.Request, res: express.Response, next) {   let err = new Error('Not Found');   next(err); });

// production error handler // no stacktrace leaked to user app.use(function(err: any, req: express.Request, res: express.Response, next: express.NextFunction) {

  res.status(err.status || 500);   res.json({
    error: {},
    message: err.message   }); });

export { app }

pruduct.ts

 import * as mongoose from 'mongoose';

interface Product{   name: String;   price: Number;   count: Number; }

interface ProductModel extends Product, mongoose.Document{};

var productShema = new mongoose.Schema({   name: String,   price: Number,   count: Number });

var Product = mongoose.model<ProductModel>("ProductList", productShema);

export = Product;

我已经安装了节点模块和打字。

0 个答案:

没有答案