0

I am working on Laravel application and trying to access jQuery via nodemodules

Here is my app.js file:

var $ = require('../../../node_modules/jquery/dist/jquery')
//require('../../../node_modules/bootstrap-sass/assets/javascripts/bootstrap.min')
require('./site')

The resulting file it generates is given here

10
  • what module loader are you using and you used npm to install jquery? Have you tried var $ = require('jquery')? Commented Aug 12, 2016 at 11:16
  • @Craicerjack I had to pass entire path as I am using it in Laravel. Ye I installed via npm. I am using browsify to use require in my file Commented Aug 12, 2016 at 11:52
  • Have you used elixir for interaction with these files - laravel.com/docs/5.2/elixir#browserify - seems Laravel has its own API for helping to deal with this stuff. Commented Aug 12, 2016 at 12:41
  • Yes I am using Elexir Commented Aug 12, 2016 at 14:02
  • This task assumes that your scripts are stored in resources/assets/js and will place the resulting file in public/js/main.js. You may pass a custom output location as an optional second argument: I think then, having elixir configured you should be able to just require('jquery') without the absolute file path Commented Aug 12, 2016 at 14:54

1 Answer 1

1

Define $ globally, like this:

window.$ = window.jQuery = require('jquery');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.