Using npm modules?


#1

I might be missing something here, but is it possible to use npm modules in the dependencies section of the package.json?


#2

Yes. But keep in mind that requiring a lot of big modules will increase the size of your package and it’s load time by quite a bit.


#3

Yes, this is an package that I created and I’m using the entities package from npm.


#4

I’m having trouble getting an NPM module to load. The module is in NPM as sloc. I am sure it can be loaded because I tried npm show sloc and it showed it.

My package.json is …

{
  "name": "line-count",
  "main": "./lib/line-count",
  "version": "0.1.0",
  "description": "Show a line count of file",
  "activationEvents": ["line-count:open"],
  "repository": "https://github.com/atom/line-count",
  "license": "GPLv3",
  "engines": {
    "atom": ">0.50.0"
  },
  "dependencies": {
    "sloc": "0.0.8"
  }
}

Weird, when I posted this I lost the bottom half. I’ll try again …

Here is the error …

Failed to activate package named 'line-count' Error: Cannot find module 'sloc'
  at Function.Module._resolveFilename (module.js:337:15)
  at Function.Module._load (module.js:279:25)
  at Module.require (module.js:363:17)

#5

You need to run apm install in the root directory of your package (same directory where your package.json is) to download the npm module for your development work. When you install your package normally, apm will take care of this step for you.


#6

thanks once again …