0

I am writing an npm module and testing it prior to publishing. I'm using the approach described in http://podefr.tumblr.com/post/30488475488/locally-test-your-npm-modules-without-publishing but am unable to get even a simple module to be required. Here's my package.json:

{
  "name": "mystuff",
  "version": "0.0.1",
  "description": "",
  "main": "./lib/index",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "MIT"
}

And here's my stupid simple index.js:

'use strict'

exports.test_call = function() {
  return "Hello Module"
}

I would expect I could simply require my module, but it fails:

> require('mystuff')
Error: Cannot find module 'mystuff'
    at Function.Module._resolveFilename (module.js:327:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:355:17)
    at require (internal/module.js:13:17)
    at repl:1:1
    at REPLServer.defaultEval (repl.js:252:27)
    at bound (domain.js:281:14)
    at REPLServer.runBound [as eval] (domain.js:294:12)
    at REPLServer.<anonymous> (repl.js:417:12)
    at emitOne (events.js:83:20)

However, it does appear the module is installed where I expect it, and it works as expected:

> require('./node_modules/mystuff')
{ test_call: [Function] }
> require('./node_modules/mystuff').test_call()

Why am I unable to require the module? What am I missing?

Todd R
  • 18,236
  • 8
  • 31
  • 39
  • I just created this package myself and installed it the way you said but was unable to reproduce the issue. I can require `mystuff` using the name of the package. I can't really see an issue with the information present. – Marcel Gwerder Jan 06 '18 at 23:41
  • Maybe you can redo the approach again from the beginning. That method sometime works. – Cedric Jan 07 '18 at 00:23
  • It might be a location that's not on my NODE_PATH https://stackoverflow.com/questions/12594541/npm-global-install-cannot-find-module – Cedric Jan 07 '18 at 00:27
  • This might work in your code : require('node_modules/mystuff'); – Cedric Jan 07 '18 at 00:29

1 Answers1

0

After upgrading node and npm (to v9.3.0/v5.5.1), this is no longer an issue.

Todd R
  • 18,236
  • 8
  • 31
  • 39