1egoman / debundle

:card_file_box: A javascript debundler. Takes a Browserify or Webpack bundle and recreates the initial, pre-bundled source.
https://www.npmjs.com/package/debundle
705 stars 145 forks source link

Cannot read property 'id' of undefined #25

Closed theunreal closed 4 years ago

theunreal commented 4 years ago

Hi, I'm trying to debundle a webpack bundeled JS file which starts with:

webpackJsonp([ 0 ], {
    11: function(e, t, n) {
        "use strict";
        Object.defineProperty(t, "__esModule", {
            value: true
        });

Is there any special configuration I need to notice?

I have the defaults for webpack:

{
  "type": "webpack",
  "entryPoint": 1,
  "knownPaths": {}
}

Not sure what else is missing.

Update: Tried the same with another file in the repo which starts with:

(function(e) {
    var t = window["webpackJsonp"];
    window["webpackJsonp"] = function n(s, i, d) {

and got this error:

* Using default AST location for webpack...
* Reading bundle...
* Decoding modules...
* Reassembling requires...
* No lookup tabie for module 0, so using identifier as require path...
* 0 => 0
C:\Users\Wonderer\AppData\Roaming\npm\node_modules\debundle\src\utils\getModuleLocation.js:98
    throw new Error(err);
    ^

Error: Don't have enough information to expand bundle into named files. The process requires the path of one of the below to be explicitly defined:
    at getModuleLocation (C:\Users\Wonderer\AppData\Roaming\npm\node_modules\debundle\src\utils\getModuleLocation.js:98:11)
    at node (C:\Users\Wonderer\AppData\Roaming\npm\node_modules\debundle\src\transformRequires.js:79:34)
    at NodePath.single (C:\Users\Wonderer\AppData\Roaming\npm\node_modules\debundle\src\extern\replace-method\index.js:42:20)
    at traverse (C:\Users\Wonderer\AppData\Roaming\npm\node_modules\debundle\node_modules\ast-types\lib\traverse.js:35:26)
    at C:\Users\Wonderer\AppData\Roaming\npm\node_modules\debundle\node_modules\ast-types\lib\traverse.js:48:13
    at C:\Users\Wonderer\AppData\Roaming\npm\node_modules\debundle\node_modules\ast-types\lib\types.js:612:18
    at Array.forEach (<anonymous>)
    at Object.exports.eachField (C:\Users\Wonderer\AppData\Roaming\npm\node_modules\debundle\node_modules\ast-types\lib\types.js:611:27)
    at traverse (C:\Users\Wonderer\AppData\Roaming\npm\node_modules\debundle\node_modules\ast-types\lib\traverse.js:42:15)
    at C:\Users\Wonderer\AppData\Roaming\npm\node_modules\debundle\node_modules\ast-types\lib\traverse.js:48:13
1egoman commented 4 years ago

Hi - this isn't a package I'm maintaining anymore, please see the readme: https://github.com/1egoman/debundle#dragon-here-be-dragons-dragon

This tool was built as a project to research how javascript bundles work, and they can be complicated. From experience, I can guess that a bundle starting with webpackJsonp with a function signature like you mentioned is most likely a chunk that goes along with a primary bundle, and not a standalone bundle on its own (that webpackJsonp is how the chunk "injects" its modules back into the main bundle context so that it can run them). Debundle never has worked on bundles like this, and due to it not being maintained any longer, this is unlikely to be something added.

therealcoder1337 commented 3 years ago

i had similar issues and the v2 branch also doesn't work. would be nice to have a notice about that in the readme. that would save the time of people thinking about trying this solution for recent webpack versions. rn it looks like it could work despite being not maintained, while in reality it doesn't work.