bevry / cson

CoffeeScript-Object-Notation. Same as JSON but for CoffeeScript objects.
Other
1.34k stars 56 forks source link

Error: Cannot find module 'cson' #81

Closed ghost closed 7 years ago

ghost commented 7 years ago

This is a really weird error I keep getting. Been digging around google trying to find a solution, but can't find one. I did a global install for cson and when I run node and attempt to import the cson module with require(), I get an error.

$ lsb_release -a
Distributor ID: Ubuntu
Description: Ubuntu 16.04.2 LTS
Release:    16.04
Codename: xenial

I did a fresh install of the latest stable versions for node and npm and updated npm afterwards. I then ran the following commands.

$ node --version
v6.10.3
$ npm --version
4.5.0
$ sudo npm install --save -g cson
/usr/bin/cson2json -> /usr/lib/node_modules/cson/bin/cson2json
/usr/bin/json2cson -> /usr/lib/node_modules/cson/bin/json2cson
/usr/lib
└─┬ cson@4.1.0 
  ├── coffee-script@1.12.5 
  ├─┬ cson-parser@1.3.5 
  │ └── coffee-script@1.12.5  deduped
  ├─┬ extract-opts@3.3.1 
  │ ├─┬ eachr@3.2.0 
  │ │ ├── editions@1.3.3  deduped
  │ │ └── typechecker@4.4.1  deduped
  │ ├── editions@1.3.3 
  │ └─┬ typechecker@4.4.1 
  │   └── editions@1.3.3  deduped
  ├─┬ requirefresh@2.1.0 
  │ └── editions@1.3.3  deduped
  └─┬ safefs@4.1.0 
    ├── editions@1.3.3  deduped
    └── graceful-fs@4.1.11 

When I went to test out if I could import the cson module, I got this output.

$ node
> var CSON = require('cson');
Error: Cannot find module 'cson'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at repl:1:12
    at sigintHandlersWrap (vm.js:22:35)
    at sigintHandlersWrap (vm.js:73:12)
    at ContextifyScript.Script.runInThisContext (vm.js:21:12)
    at REPLServer.defaultEval (repl.js:346:29)
    at bound (domain.js:280:14)
> 

Any help with this would be greatly appreciated. Keep in mind, I am still new to using node.

balupton commented 7 years ago

Installing node globally (the -g flag) gives you access to it via the command line, but not via require.

To get access to a package via require it must be installed in the current directory's node_modules, or the node_modules of an ancestor's directory.

To install a package locally, you would remove the -g flag. If you are starting a new node project, then you would want to have a package.json file that can be created by npm init

For more information see https://nodejs.org/api/modules.html