Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require.main.filename is undefined #3

Closed
hsiliev opened this issue Jan 25, 2018 · 2 comments
Closed

require.main.filename is undefined #3

hsiliev opened this issue Jan 25, 2018 · 2 comments

Comments

@hsiliev
Copy link

hsiliev commented Jan 25, 2018

I'm trying to dump heap or cpu profile and get:

/workspace/cf-abacus/node_modules/node-oom-heapdump/lib/index.js:66
      cmd: path.dirname(require.main.filename),
                                     ^

TypeError: Cannot read property 'filename' of undefined
    at NodeOomHeapDumpImpl._callWorker (/workspace/cf-abacus/node_modules/node-oom-heapdump/lib/index.js:66:38)
    at NodeOomHeapDumpImpl.createHeapSnapshot (/workspace/cf-abacus/node_modules/node-oom-heapdump/lib/index.js:113:17)
    at NodeOomHeapdumpAPI.createHeapSnapshot (/workspace/cf-abacus/node_modules/node-oom-heapdump/index.js:31:23)
    at process.on (/workspace/cf-abacus/node_modules/abacus-webapp/src/index.js:134:21)
    at emitNone (events.js:111:20)
    at process.emit (events.js:208:7)
    at Signal.wrap.onsignal (internal/process.js:208:44)

Running on:
macOS 10.13.2
node 8.9.4
yarn 1.3.2

@paulrutter
Copy link
Contributor

paulrutter commented Jan 25, 2018

I guess this is the case when the module is used from another module, and not directly from the main app. Good find.
PR for this is welcome, since i'm not having much time to fix this coming days.

Maybe we can make the code more robust by checking if require.main is null and if so, use process.cwd (https://nodejs.org/api/process.html#process_process_cwd)? Or just use https://www.npmjs.com/package/require-main-filename?

paulrutter added a commit that referenced this issue Feb 13, 2018
Upgrade dependencies
@paulrutter
Copy link
Contributor

Closed, fixed with a new release https://github.com/blueconic/node-oom-heapdump/releases/tag/1.0.12.
It now uses 'https://www.npmjs.com/package/require-main-filename' instead of using require.main.filename.

@hsiliev can you verify that this fixes your issue? Just use the latest version 1.0.12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants