简体   繁体   中英

Heroku error: Cannot find module 'optimizer' causing internal server error

I'm trying to deploy my node.js app on Heroku and when i open it, it gives me an internal server error . When i check the logs, t says Cannot find module optmizer . I don't use anything called optmizer in the project. When running it on localhost, it works perfectly but no idea as to why it asking about a missing module. I've also tried installing the optmizer module but doesn't seem to do anything

app.js

const createError = require('http-errors');
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const logger = require('morgan');
const indexRouter = require('./routes/index');
const usersRouter = require('./routes/users');
const flash = require('connect-flash');
const session = require('express-session');
const app = express();
app.use(flash());

app.use(session({
  cookie: { maxAge: 6000 },
  secret: 'futuresonic',
  resave: false,
  saveUninitialized: false
}));

app.get('/', (req, res) => {
  res.render('index', { title: 'MyWebApp', message: req.flash('success'), sessionFlash: res.locals.sessionFlash});
});

app.get('/done', (req, res) => {
  res.render('done');
});

app.use((req, res, next) => {
  res.locals.success = req.flash('success');
  res.locals.info = req.flash('info');
  res.locals.errors = req.flash('error');
  res.locals.user = req.user || null;
  next();
});

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/js', express.static(__dirname + '/node_modules/bootstrap/dist/js'));
app.use('/css', express.static(__dirname + '/node_modules/bootstrap/dist/css'));
app.use('/', indexRouter);
app.use('/users', usersRouter);

app.use((req, res, next) => {
  next(createError(404))
});

app.use((err, req, res, next) => {
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};
  res.status(err.status || 500);
  res.render('error');
});

module.exports = app;

package.json

{
  "name": "MyWebApp",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "body-parser": "^1.18.3",
    "bootstrap": "^4.3.1",
    "connect-flash": "^0.1.1",
    "cookie-parser": "~1.4.3",
    "debug": "~2.6.9",
    "express": "~4.16.0",
    "express-session": "^1.15.6",
    "express-validator": "^5.3.1",
    "firebase": "^5.8.6",
    "firebase-admin": "^7.0.0",
    "flash": "^1.1.0",
    "http-errors": "~1.6.2",
    "morgan": "~1.9.0",
    "nodemon": "^1.18.10",
    "pug": "^2.0.3"
  },
  "devDependencies": {
    "@types/express": "^4.16.1",
    "@types/node": "^11.11.3"
  }
}

Heroku logs

2019-03-15T11:35:26.247394+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2019-03-15T11:35:26.247433+00:00 app[web.1]: designed for a production environment, as it will leak
2019-03-15T11:35:26.247436+00:00 app[web.1]: memory, and will not scale past a single process.
2019-03-15T11:35:26.981657+00:00 heroku[web.1]: State changed from starting to up
2019-03-15T11:35:28.691683+00:00 heroku[router]: at=info method=GET path="/" host=pure-hamlet-86611.herokuapp.com request_id=1bcb11de-4b03-44fd-9835-7b48f0e2bf4b fwd="109.69.85.106" dyno=web.1 connect=1ms service=129ms status=500 bytes=569 protocol=https
2019-03-15T11:35:28.690100+00:00 app[web.1]: Error: Cannot find module './optimizer/level-0/optimize'
2019-03-15T11:35:28.690112+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
2019-03-15T11:35:28.690115+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:508:25)
2019-03-15T11:35:28.690117+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:637:17)
2019-03-15T11:35:28.690118+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:22:18)
2019-03-15T11:35:28.690120+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/clean-css/lib/clean.js:8:22)
2019-03-15T11:35:28.690122+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:701:30)
2019-03-15T11:35:28.690124+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
2019-03-15T11:35:28.690125+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:600:32)
2019-03-15T11:35:28.690127+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
2019-03-15T11:35:28.690129+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:531:3)

I got this error message after updating my version of pug to 2.0.3 and running npm audit . Not sure why. To fix I changed my package.json pug version to 2.0.0, deleted my package-lock.json, and recreated it using npm install .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM