readium / readium-js-viewer

👁 ReadiumJS viewer: default web app for Readium.js library
BSD 3-Clause "New" or "Revised" License
550 stars 186 forks source link

How to import / use node module package inside src/js file #638

Closed rudra0713 closed 7 years ago

rudra0713 commented 7 years ago

Let's say I have a javascript file named EpubReader.js inside my src directory and I want to use an already installed node module package (ex : require-dir, lodash etc) in my js file. What is the appropriate way to do this ? I have been trying something like this -

var dir = require("require-dir") and I received this error "no require-dir" . Although it is installed in my node module directory. But, if I copy this simple line in a sample index.js file and run it using node command, it works without any error.

danielweck commented 7 years ago

The Readium JavaScript code is written using AMD (Asynchronous Module Definitions), not Node CommonJS.

Furthermore, this is JavaScript for web browser runtime, not NodeJS / server environment (different set of APIs / libraries).