-
Notifications
You must be signed in to change notification settings - Fork 84
Cannot read property 'warn' of undefined when preferBuiltins is not set #196
Description
rollup-plugin-node-resolve/src/index.js
Lines 177 to 183 in 73b01b1
| if ( !isPreferBuiltinsSet ) { | |
| this.warn( | |
| `preferring built-in module '${importee}' over local alternative ` + | |
| `at '${resolved}', pass 'preferBuiltins: false' to disable this ` + | |
| `behavior or 'preferBuiltins: true' to disable this warning` | |
| ); | |
| } |
When not having preferBuiltins set, I have a case where this piece of code throws an error
Plugin Error: Cannot read property 'warn' of undefined
Can't give a reproducible example right now but just wondering whether this is considered a bug, or whether I'm doing something wrong to have this (the plugin context) being undefined? I just changed the resolveId hook to log if this === undefined and there were heaps of modules where that was the case, so I'm wondering whether there should be a 'warn' in this check before trying to throw a warning?
As a workaround, setting preferBuiltins (to either true or false) does the trick.
Edit: The package/importee that caused this was events as a dependency of @featherjs/feathers, and the resolveId hook was called three times. The first time this was working and the warning came through, but then it was called again and that's when this was undefined...
This is the error being thrown:
{ TypeError: Cannot read property 'warn' of undefined
at <line number that refers to the quoted code above>
at <anonymous> code: 'PLUGIN_ERROR', plugin: 'commonjs', hook: 'resolveId' }
So I think the calls actually came from rollup-plugin-commonjs (does it use node-resolve?), and maybe that's why this isn't set within node-resolve, because the context is a different plugin (commonjs)?