0

I have problem with log4js.

Problem is that when i ran node.sj error pops up:

Error: Cannot find module 'log4js'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/home/bot/site.js:2:14)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)

So i instaled log4js with:

npm install log4js

And now the real error is here:

/home/bot/node_modules/log4js/lib/log4js.js:25
const debug = require('debug')('log4js:main');
^^^^^
SyntaxError: Use of const in strict mode.
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/home/bot/site.js:2:14)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)

Maybe i have broken bot. But bot should be OK.

I had this error in past but i fixed it and do not know how. (about 2years ago?) and error was in bot folder i think.

i have Debian 7 installed on server Thx for response.

1 Answers1

0

which version of node.js are you running?

node --version

First of all try to install your application packages with npm install log4j --save (to save it in your package.json).

It seems that you are using an old version of node.js!

Using this site you can see when the keyword const was introduced without requiring the strict keyword!

http://node.green/#ES2015-bindings-const

To fix the error just need to update your node.js to the latest stable version.

Another solutions: (The previous one is my favourite).

You can set a single specific file to be strict by writing 'use strict' on top of your file.

Or you can force to run your whole application to strict by using node --use_strict index.js (I wont recommend this one)

Marco Talento
  • 2,335
  • 2
  • 19
  • 31