cannot find module 'cookie' while using the express module

安稳与你 提交于 2019-12-11 00:03:15

问题


I need your help on building rest API using express.. I have tried many versions of express. that also have CookieParser middleware but I'm just getting the above error...

  Error: Cannot find module 'cookie'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)`

I installed the cookie-parser globally and using Express version 4.... the code snippet is below.

var express = require('express'),
cookieParser = require('cookie-parser'),
bodyParser = require('body-parser'),
session = require('express-session'),
mongoose = require('mongoose'),
api = require('./routes/api.js') ,  
app = express();

app.use(session({ secret: 'angcms', saveUninitialized: true, resave: true })); app.use(cookieParser());


回答1:


It sounds like npm has screwed up your module installation is all. Try reinstalling this module completely.

Uninstalling complete module

$ npm uninstall cookie-parser

after uninstalling the module, install it again using below command

$ npm install cookie-parser -g

Note: if you have not installed before then install first and the execute .




回答2:


I had the same situation. I solved by this way:

$ npm install

You must type this inside the Project folder. If i understood, "npm install" check the project dependencies registered on JSON files.




回答3:


To solve this probleme, create another projet and install cookie or open other project that have cookie installed and open node_module and copy the folder cookie and replace it. This problem happens because you have npm and yarn installed if you open the node module folder, the cookie folder is empty because yarn or npm did not install the package



来源:https://stackoverflow.com/questions/33152297/cannot-find-module-cookie-while-using-the-express-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!