rollup / rollup-plugin-commonjs

This module has moved and is now available at @rollup/plugin-commonjs / https://github.com/rollup/plugins/blob/master/packages/commonjs
MIT License
501 stars 126 forks source link

key `MemberExpression` does not exist in `extractors` #376

Closed RebeccaStevens closed 5 years ago

RebeccaStevens commented 5 years ago

I don't know what's causing this but I'm getting an error on this line:

https://github.com/rollup/rollup-plugin-commonjs/blob/e4eb949e50ada8c3c7d8606dedfbf28db1255209/src/ast-utils.js#L47

Here's the console output:

/path/to/project/node_modules/rollup-plugin-commonjs/src/ast-utils.js:46
                node.properties.forEach(prop => {
                  ^
TypeError: extractors[prop.value.type] is not a function
    at /path/to/project/node_modules/rollup-plugin-commonjs/src/ast-utils.js:52:24
    at Array.forEach (<anonymous>)
    at ObjectPattern (/path/to/project/node_modules/rollup-plugin-commonjs/src/ast-utils.js:46:19)
    at extractNames (/path/to/project/node_modules/rollup-plugin-commonjs/src/ast-utils.js:36:23)
    at Object.enter (/path/to/project/node_modules/rollup-plugin-commonjs/dist/rollup-plugin-commonjs.cjs.js:453:4)
    at visit (/path/to/project/node_modules/estree-walker/src/estree-walker.js:22:9)
    at visit (/path/to/project/node_modules/estree-walker/src/estree-walker.js:44:4)
    at visit (/path/to/project/node_modules/estree-walker/src/estree-walker.js:39:5)
    at visit (/path/to/project/node_modules/estree-walker/src/estree-walker.js:44:4)
    at visit (/path/to/project/node_modules/estree-walker/src/estree-walker.js:44:4)

After doing some debugging it seems that extractors is missing the key MemberExpression. Here is how these values evaluate:

prop.value.type === "MemberExpression"

extractors = {
  Identifier: // [Function: Identifier],
  ObjectPattern: // [Function: ObjectPattern],
  ArrayPattern: // [Function: ArrayPattern],
  RestElement: // [Function: RestElement],
  AssignmentPattern: // [Function: AssignmentPattern]
}

extractors[prop.value.type] === undefined
RebeccaStevens commented 5 years ago

Adding:

MemberExpression: function MemberExpression(names, node) {
  extractors[node.property.type](names, node.property);
}

to extractors sends me into an infinite loop so I don't know what's going wrong. The issue may end up have nothing to do with this repo.

RebeccaStevens commented 5 years ago

After playing around with my rollup config for quite a while I now have a working build. I've still got know idea what was causing this original issue though.

Feel free to close this issue if you believe there is no need for MemberExpression to exist on extractors.

antstanley commented 5 years ago

+1 on this issue. Hit it today but in rollup-plugin-commonjs.cjs.js

TypeError: extractors[prop.value.type] is not a function in /node_modules/rollup-plugin-commonjs/dist/rollup-plugin-commonjs.cjs.js

I managed to get Rollup working by adding the code you put above

MemberExpression: function MemberExpression(names, node) {
        extractors[node.property.type](names, node.property);
    },

But the code I've now successfully bundled doesn't work...

If I exclude the offending module (in my case @azure/cosmos) everything works without the patch... So that's my current workaround