Home>

I wanted to execute file writing with javascript in the rails view, and after examining various things, I found that it was possible to use node.js, so I tried it.

Error message

When I tried to use the following preparations, I got a browserify related error.

(1) node.js is already installed (installed when building the rails environment)
(2) Install browserify
(3) Install browserify-rails

When the page is displayed in the browser, the following error occurs.

Unable to run node_modules/.bin/browserify.Ensure you have installed it with npm.

-I moved the js file for writing files from the command prompt.
$node sample.js

const fs = require ('fs')
fs.writeFileSync ("output.txt", "hello, world")

-The file join operation using browserify from the command prompt has been successfully completed.
$browserify main.js -o build.js

Supplemental information (FW/tool version etc.)

(OS) Windows 10
(WSL) Ubuntu 18.04.2 LTS
(Rails) 6.0.1
(ruby) 2.5.1p57
(browserify) 4.3.0
(node.js) v11.14.0
(npm) 3.5.3

Points of interest

There was an error message "Unable to run node_modules/.bin/browserify."
When I checked the above path, there was no browserify in ./bin.
(Path: app/node_modules/.bin /)

Thank you for helping me if you understand the possible cause (´;ω;`)

  • Answer # 1

    Although browserify is probably installed in the global area,
    When Rails browses browserify, it looks for the node_module under the project directory, so browserify is not found under node_modules and it seems that an error has occurred.

    In the project directory,

    npm install -S browserify
    Run

    to try a local installation of browserify.