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

util.inspect: cannot read property 'options' of null #740

Closed
pi0 opened this issue Mar 9, 2019 · 2 comments
Closed

util.inspect: cannot read property 'options' of null #740

pi0 opened this issue Mar 9, 2019 · 2 comments
Labels

Comments

@pi0
Copy link

pi0 commented Mar 9, 2019

When using esm programmatically, passing any options object as second arg breaks util.inspect().

I've tried versions one by one. This bug seems to be introduced by 3.2.11...3.2.12. Downgrading to 3.2.11 fixes problem but any version equal or higher to 3.2.12 has this problem.

Additional info:

  • OS: Ubuntu/Linux
  • Node: v11.10.1

Repo:

a.js

require('esm')(module)('./inspect.js')

b.js

require('esm')(module, {})('./inspect.js')

inspect.js

import { inspect } from 'util'

inspect({})

// originally also fails with CJS:
// require('util').inspect({})

Running node a.js seems fine but node b.js throws this error:

TypeError: Cannot read property 'options' of null
    at Object.<anonymous> (/home/pooya/tmp/esm-inspect/inspect.js:1)
    at Generator.next (<anonymous>)

With debug enabled:

var __global__ = this;(function (require, module, __shared__) { var __shared__;const e=module,t={Array:global.Array,Buffer:global.Buffer,Error:global.Error,EvalError:global.EvalError,Function:global.Function,JSON:global.JSON,Object:global.Object,Promise:global.Promise,RangeError:global.RangeError,ReferenceError:global.ReferenceError,Reflect:global.Reflect,SyntaxError:global.SyntaxError,TypeError:global.TypeError,URIError:global.URIError,eval:global.eval},r=global.console;module.exports=(function(e){var t={};function r(i){if(t[i])return t[i].exports;var n=t[i]={i:i,l:!1,exports:{}};return e[i].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.d=function(e,t,r){Reflect.defineProperty(e,t,{configurable:!0,enumerable:!0,get:r})},r.n=function(e){return e.a=e,function(){return e}},r(r.s=2)})([(function(e,t){var r;t=e.exports=H,"object"==typeof process&&process,r=function(){},t.SEMVER_SPEC_VERSION="2.0.0";var i=256,n=Number.MAX_SAFE_INTEGER||9007199254740

TypeError: Cannot read property 'options' of null
    at s (/home/pooya/tmp/esm-inspect/node_modules/esm/esm.js:1:192718)
    at Proxy.i (/home/pooya/tmp/esm-inspect/node_modules/esm/esm.js:1:190967)
    at Proxy.<anonymous> (/home/pooya/tmp/esm-inspect/node_modules/esm/esm.js:1:194574)
    at Object.apply (/home/pooya/tmp/esm-inspect/node_modules/esm/esm.js:1:194364)
    at Object.<anonymous> (/home/pooya/tmp/esm-inspect/inspect.js:1:17)
    at Object.<anonymous> (/home/pooya/tmp/esm-inspect/node_modules/esm/esm.js:1:244937)
    at /home/pooya/tmp/esm-inspect/node_modules/esm/esm.js:1:239014
    at Generator.next (<anonymous>)
    at su (/home/pooya/tmp/esm-inspect/node_modules/esm/esm.js:1:239353)
    at pu (/home/pooya/tmp/esm-inspect/node_modules/esm/esm.js:1:241564)
@pi0
Copy link
Author

pi0 commented Mar 9, 2019

For history, this issue is breaking mongoose Document.prototype.toString when being used in an ESM environment which was programmatically created.

@jdalton
Copy link
Member

jdalton commented Mar 9, 2019

If I had to guess it looks like the error is coming from this line. I'll dig in.

Update:

Confirmed

Update:

I've fixed the issue locally, though working through the affects of it.

Update:

Patches 7f3f4b2, 70bac76; Tests 9a9a90e;

Update:

esm v3.2.15 is released 🎉

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

No branches or pull requests

2 participants