jspm / registry

The jspm registry and package.json override service
https://jspm.io
229 stars 255 forks source link

The inherits module throws a TypeError exception #851

Closed deeleman closed 8 years ago

deeleman commented 8 years ago

This issue is probably unrelated to JSPM or SystemJs and my guess is that it's caused by an exception propagated by an outdated dependency within another dependency, but I've been banging my head against the wall for a while now and would appreciate some help.

I have an exception that breaks the whole application in an ES2015 project that has been working seamlessly on top of JSPM and SystemJS+Babel up to now. Surprisingly this issue only occurs upon loading the modules with System.import() and not after bundling them with the --sfx flag.

I get the following stack trace:

system.js:4 Uncaught (in promise) Error: TypeError: Object prototype may only be an Object or null: undefined
        at Object.inherits (http://localhost/libs/packages/npm/inherits@2.0.1/inherits_browser.js:6:29)
        at eval (http://localhost/libs/packages/npm/readable-stream@1.1.13/lib/_stream_readable.js:22:8)
        at Object.eval (http://localhost/libs/packages/npm/readable-stream@1.1.13/lib/_stream_readable.js:623:3)
        at eval (http://localhost/libs/packages/npm/readable-stream@1.1.13/lib/_stream_readable.js:625:4)
        at eval (http://localhost/libs/packages/npm/readable-stream@1.1.13/lib/_stream_readable.js:626:3)
    Evaluating http://localhost/libs/packages/npm/readable-stream@1.1.13/lib/_stream_readable.js
    Evaluating http://localhost/libs/packages/npm/readable-stream@1.1.13/readable.js
    Evaluating http://localhost/libs/packages/npm/stream-browserify@1.0.0/index.js
    Evaluating http://localhost/libs/packages/npm/stream-browserify@1.0.0.js
    Evaluating http://localhost/libs/packages/github/jspm/nodelibs-stream@0.1.0/index.js
    Evaluating http://localhost/libs/packages/github/jspm/nodelibs-stream@0.1.0.js
    Evaluating http://localhost/libs/packages/npm/through@2.3.8/index.js
    Evaluating http://localhost/libs/packages/npm/through@2.3.8.js
    Evaluating http://localhost/libs/packages/npm/regenerator@0.8.40/main.js
    Evaluating http://localhost/libs/packages/npm/regenerator@0.8.40.js
    Evaluating http://localhost/libs/packages/npm/babel-core@5.8.38/lib/transformation/transformers/other/regenerator.js
    Evaluating http://localhost/libs/packages/npm/babel-core@5.8.38/lib/transformation/transformers/index.js
    Evaluating http://localhost/libs/packages/npm/babel-core@5.8.38/lib/transformation/index.js
    Evaluating http://localhost/libs/packages/npm/babel-core@5.8.38/lib/api/node.js
    Evaluating http://localhost/libs/packages/npm/babel-core@5.8.38/index.js
    Evaluating http://localhost/libs/packages/npm/babel-core@5.8.38.js
    Error loading http://localhost/libs/packages/npm/babel-core@5.8.38.js
    Error loading http://localhost/app/main.js

Being http://localhost/app/main.js the file that triggers the first main System.import(). Appending system-polyfills.js prior to system.js throws a slightly elaborated message (with the same stack-trace tho):

system-polyfills.src.js:1276 Potentially unhandled rejection [4] TypeError: Object prototype may only be an Object or null: undefined

All promises throughout my application are properly handled to catch and log errors, although I do not get any log from there and the stack trace above is my only reference. FYI the promise returned by System.import() has been handled as well in order to catch errors but this issue seems to take place earlier in the execution flow.

Has anyone run into a similar issue with the inherits package? Thanks in advance for your help.

deeleman commented 8 years ago

I have the gut feeling this might be caused by the way I was transpiling ES6 code into ES5 on runtime. I've tried to find a walkthrough on how to configure SystemJS and JSPM to transpile ES6 on runtime and I only found this, that seems to supersede the old, pre-babel-presets model I had been using before noticing this issue (the project had not been updated in a while):

System.config({
   transpiler: 'babel'
});

Could anyone point me to a more thorough walkthrough on how to configure SystemJS+JSPM to execute transpilation on runtime? I've followed the guidelines linked above and get an error when Babel requires Traceur.

Any hint about this or the exception posted above will be appreciated.

deeleman commented 8 years ago

Closed, as refactoring the way ES2015 is transpiled seemed to solve the issue.