Nabeel Abbas
Nabeel Abbas

Reputation: 41

how to require some npm modules into my js file

i have this index.jade file

  include scripts
  script( src='path of my site/project name/src/scripts/index.js' )

and also index.js file

var _ = require('./underscore');

var IScroll = require('iscroll/build/iscroll-probe.js');

var zepto = require('./vendor/zepto.js');

var morpheus = require('morpheus');

var easings = require('./vendor/morpheus-easings.js');

require('./vendor/zepto.touch.js');

I am getting ReferenceError: require is not defined I want to include modules for the correct working any help ?

Upvotes: 1

Views: 275

Answers (2)

nuway
nuway

Reputation: 2394

The type of require you are looking to use is the node type. You can't use it directly in your browser. You need to get a bundler such as browserify or webpack, which would convert those requires to actual dependencies behind the scenes. Here's an article that would get you started with browserify.

Upvotes: 1

Trip
Trip

Reputation: 27114

First :

npm install iscroll --save

Then this :

global.IScroll = require('iscroll');

Upvotes: 1

Related Questions