Search code examples
node.jslaravelsqlitelaravel-echo

Cannot find module 'node-v46-linux-x64/node_sqlite3.node' error in laravel-echo-server


I have to set laravel-echo-server in my laravel project. I have successfully installed it and it is running perfectly while I'm running from terminal. But while running from supervisor, it throws error

Cannot find module 'node-v46-linux-x64/node_sqlite3.node'

I have almost spend two days to solve this issue. But I didn't get success. So if anyone know the answer, it will be appreciated.

Here are all step/configuration details.

  1. Install node 7.10.0 (https://github.com/nodejs/help/wiki/Installation)
  2. Install laravel-echo-server globally and initialise it in my project

After these steps, if I run 'laravel-echo-server start' from terminal, it gets run perfectly.

Now I have to set this command in supervisor. So i have performed these steps.

  1. create symlink of laravel-echo-server (sudo ln -s /usr/lib/nodejs/node-v7.10.0/lib/node_modules/laravel-echo-server/bin/server.js /usr/bin/laravel-echo-server)

  2. set 'laravel-echo-server start' command in supervisor

    Here are supervisor details.

    File location: /etc/supervisor/conf.d/laravel.conf

    [program:laravel-echo-server]
    command=/usr/bin/laravel-echo-server start --dir=/var/www/html/laravel
    autostart=true
    autorestart=true
    stderr_logfile=/var/www/html/laravel/laravel-echo-server-err.log
    stdout_logfile=/var/www/html/laravel/laravel-echo-server-out.log
    
  3. Run sudo supervisorctl reread and sudo supervisorctl update

  4. Run sudo supervisorctl start laravel-echo-server

But it throws error. Here is error log.

Error: Cannot find module '/usr/lib/nodejs/node-v7.10.0/lib/node_modules/laravel-echo-server/node_modules/sqlite3/lib/binding/node-v46-linux-x64/node_sqlite3.node'
    at Function.Module._resolveFilename (module.js:326:15)
    at Function.Module._load (module.js:277:25)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/lib/nodejs/node-v7.10.0/lib/node_modules/laravel-echo-server/node_modules/sqlite3/lib/sqlite3.js:4:15)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/lib/nodejs/node-v7.10.0/lib/node_modules/laravel-echo-server/dist/database/sqlite.js:3:15)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)

There is node-v51-linux-x64 directory in /usr/lib/nodejs/node-v7.10.0/lib/node_modules/laravel-echo-server/node_modules/sqlite3/lib/binding.


Solution

  • Finally I have fixed this issue. I have followed this steps.

    1. Completly uninstall nodejs, npm and node
    2. Installing Node.js via package manager

    I have run this commands in step 2.

    1. curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
    2. sudo apt-get install -y nodejs
    3. sudo apt-get install -y build-essential

    Then I have installed laravel-echo-server. And everything works fine for me. But if you get permission error, you should run sudo chown -R $USER /usr/lib/node_modules. and run sudo ln -sfn ../lib/node_modules/laravel-echo-server/bin/server.js /usr/bin/laravel-echo-server in case of symlink error.