Skip to content

Error: Cannot find module, despite NODE_PATH being set #135

@janstrohbeck

Description

@janstrohbeck

Description

I use Typescript with a basePath setting, so that I can require my files from an absolute base path:

import navigation from 'redux/interfaces/navigation'

This gets transpiled to:

const _navigation = require('redux/interfaces/navigator')

The redux folder is in ./src/internal, so I have to set NODE_PATH accordingly.

I want to use iron-node to debug my mocha unit test, which I can execute like this:

NODE_PATH=./src/internal node node_modules/mocha/bin/_mocha --opts mocha.opts 'tests/**/*.spec.ts' 'tests/**/*.spec.tsx'

This works, but if I replace node with iron-node, it cannot find the files in ./src/internal (see error log below)

Steps to Reproduce

I reproduced the issue with the following 2-file setup:

  1. Create file src/internal/redux/interfaces/navigation.js:
 module.exports = {
    a: true
}
  1. Create file test/test.js:
const _navigation = require('redux/interfaces/navigation')
console.log(_navigation.a)
  1. Execute in shell (runs without errors): NODE_PATH=./src/internal node test/test.js
  2. Execute in shell (fails with module not found): NODE_PATH=./src/internal iron-node test/test.js

Expected behavior: [What you expect to happen]

iron-node should run without errors and find the required file.

Actual behavior: [What actually happens]

iron-node does not find the required file.

Reproduces how often: [What percentage of the time does it reproduce?]

Always.

Screenshot(s): [Screenshot(s) or animated gifs of the error situtaion]

Error log(s): From devTools console or shell terminal

app.js:197 ironNode boot
/usr/lib/node_modules/iron-node/app/require-custom-wrap.js:32 Object {v8: Object, app: Object, workSpaceDirectory: function}
app.js:268 ModedModule {}
app.js:58   Error: Cannot find module 'redux/interfaces/navigation'
  
  - reset-search-paths.js:35 Function.Module._resolveFilename
    [lib]/[iron-node]/[electron]/dist/resources/electron.asar/common/reset-searc    h-paths.js:35:12
  
  - module.js:20 require
    internal/module.js:20:19
  
  - test.js:1 Object.<anonymous>
    /tmp/test-project/test/test.js:1:176
  
  - test.js:3 Object.<anonymous>
    /tmp/test-project/test/test.js:3:3
  

error @ app.js:58
emitOne @ events.js:96
emit @ events.js:191
window.onerror @ /usr/lib/node_modules/iron-node/node_modules/electron/dist/resources/electron.asar/renderer/init.js:135
app.js:59 Details Error: Cannot find module 'redux/interfaces/navigation'
    at Module._resolveFilename (module.js:470)
    at Function.Module._resolveFilename (/usr/lib/node_modules/iron-node/node_modules/electron/dist/resources/electron.asar/common/reset-sea…:35)
    at Function.Module._load (module.js:418)
    at Module.require (module.js:498)
    at require (internal/module.js:20)
    at Object.<anonymous> (/tmp/test-project/test/test.js:1)
    at Object.<anonymous> (/tmp/test-project/test/test.js:3)
    at Module._compile (module.js:571)
    at Object.Module._extensions..js (module.js:580)
    at Module.load (module.js:488)
error @ app.js:59
emitOne @ events.js:96
emit @ events.js:191
window.onerror @ /usr/lib/node_modules/iron-node/node_modules/electron/dist/resources/electron.asar/renderer/init.js:135

Version(s)

versions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions