Parcel: Option to apply transforms to third-party node_modules

Created on 13 Sep 2018  路  10Comments  路  Source: parcel-bundler/parcel

馃檵 feature request

One feature that is seriously lacking is the ability to apply transforms to third-party node_modules. As previously stated:

This even works in third-party node_modules: if a configuration file is published as part of the package, the transform is automatically turned on for that module only.
Parcel Docs

It seems as if Parcel has the ability but not the option to achieve this. The issue has been discussed before, however, it did not apply to third-party node_modules.
It seems that I am not alone... (& also)

馃 Expected Behavior

If specified, Parcel will apply transforms on the third party node_modules before bundling.

馃槸 Current Behavior

Right now Parcel is unable to recognize the object spread operator in third-party node_modules because Parcel does not transform the third party node_module before bundling. Thus, when importing third party node_modules that do not have a .babelrc & they use the ...(obj) operator then the build will fail:

馃毃  ../node_modules/ky/index.js:21:19: Unexpected token (21:19)
  19 |                          }
  20 |
> 21 |                          returnValue = {...returnValue, [key]: value};
     |                                         ^
  22 |                  }
  23 |          }
  24 |  }

馃拋 Possible Solution

CLI:
parcel build index.js --include <3rd party module>
API:

// Bundler options
const options = {
  transforms: [
    'node_module_a',
    'node_module_b',
  ]
}

Apply to all external modules:

let ext_modules = Object.keys(require('./package.json').dependencies)
// Bundler options
const options = {
  transforms: ext_modules
}

馃敠 Context

I am trying to use Parcel to build for node _and_ browser.

馃捇 Examples

If a dev could point me in the right direction I could begin implementation immediately. Thank you.

Feature

Most helpful comment

@DeMoorJasper why was this closed? From what I could find, the source field only works for linked modules not third party modules

All 10 comments

I would find this extremely useful for the various packages out there that are ES6 but don't work with Parcel's default behavior, like delay.

Spread will be applied to node_modules by default already in parcel 1.10, which isn't released yet.

But in the future Parcel 2+ it will definitely be possible to transform node_modules, and with linked modules it's already possible using the source field

@DeMoorJasper Awesome! That is great to hear. When will 1.10 be released? Where is this source field? I don't see it in the docs. Thanks! 馃憤

It's kinda documented here: https://github.com/parcel-bundler/parcel/pull/1101 But it never ended up in the docs, feel free to contribute it

@DeMoorJasper why was this closed? From what I could find, the source field only works for linked modules not third party modules

This is still a major problem!

I wasted more than two hours debugging UW-Macrostrat/ui-components#1 because the real issue was totally obscured by the inconsistency between symlinked and third-party modules: I repeatedly developed a working bundler strategy with an npm linked version of my module, only to push to NPM and have ES6 code silently included in my browser app. For this workflow, the hard-coded differences in treatment of symlinked modules are counterproductive and unexpected.

The title of this issue is Option to apply transforms to third-party node_modules, it has not fixed. 馃 Is there a solution.

@DeMoorJasper or @taylorjdawson, can this be reopened?

@DeMoorJasper This is still not fixed, worth to reopen?

To all the people asking for this to be re-opened, as the original post mentions, https://github.com/parcel-bundler/parcel/issues/1655 is open and targets the same problem.

So you could just subscribe/follow what is happening in there instead, even if there's not much activity towards implementing this feature there either.

Was this page helpful?
0 / 5 - 0 ratings