-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discuss .babelrc detection, engines field, etc. #13
Comments
As i understand the fundamental issue here is to detect how much transpilation (if any) is needed for each third party dependency, correct? Stop me if it's stupid but couldn't we somehow check |
Whether or not to honor In short, most npm packages are fully compiled before they are published, so it is wasteful/inappropriate to recompile them (even using their own For the minority of npm packages that do need to be recompiled for the browser, the application developer needs to be able to intervene somehow, to enable recompilation selectively. I can imagine various ways of configuring that behavior, but it may be hard/impossible to make the right choices without increasing the configuration burden somewhat. Taking a step back: Parcel is competing with Webpack, which is known for using configuration to solve any and all problems. While "zero-configuration" may be more of a goal than a reality (you still have to configure packagers, e.g.), I think it's a really valuable goal, so it's worth thinking hard about how to solve this problem with minimal additional configuration. |
@benjamn So do I understand correctly that the issue lies in whether it is necessary to recompile given dependency and if so using which It does seem like a band-aid of some kind though... |
I'm generally against doing any kind of transforms on Basing things off of I suppose if someone shipped: {
"engines": {
"ecmascript": "2017"
}
} We could deal with that a bit easier since we can polyfill and transform all the relevant bits. I'm still not convinced that's a good idea. |
Does Babel currently transpile node_modules? |
@davidnagli Babel itself defaults to ignoring |
This is currently causing some issues for me. All the 3rd party modules I import (from |
@chipit24 I guess we’re gonna have to work on resolving this issue. In the meantime, if you’re looking for a workaround use the |
I've always understood that the 'main' property in package.json should point to an es5 build, so transpilation should not be necessary. Is this not the correct assumption? |
There's no real requirement for what the
|
I see. My opinion is that parcel should see packages as read only and not run any transformations on content in them unless this is explicit in some way. |
@davidnagli Could you specify how to use the |
Also, a common problem is that people accidentally publish their node_modules with .babelrc even if it is already transpiled. Additionally, let us say we have package X which uses I think that a flag to disable this behavior would be very helpful (or have this behavior prevented by default and allow it to be toggled on). Also, I'm not quite sure what the |
It would be great to have an option to bypass I've created a minimal example of it breaking the build: https://github.com/Cinamonas/parcel-babelrc-issue Is there currently any workaround? Because if you do import a transpiled module that also includes |
Any progress on a workaround? This seems like a pretty critical issue which makes parcel more-or-less unusable in many situations. To be clear, my issue is:
One (of many!) examples is the
It has a .babelrc file, but it also includes the already compiled output; no transpiling is needed. |
The solution is to submit a PR to those projects asking them to remove their .babelrc file from their npm deployment.
Just kidding.
There are two issues to consider:
1. When we load config files, we try to load the one closest to a given file. Parcel walks up the filesystem from the source file until locating the config.
2. This is the correct behavior in all cases except for transpiled code. Ideally, we would detect that we're importing code that has already been run through a compiler, and therefore shouldn't compile it again.
It would be a bad idea to do a simplistic, hacky solution such as "just ignore all node_modules/*/.babelrc files". For example, source code is shipped along with transpiled code, and right now you can just point the package.json to the source folder instead of the transpiled folder and everything will just work. Parcel picks up on their babelrc correctly.
On the other hand, I'm not sure whether there's a reliable way to detect whether a js file has already been transpiled. Does babel insert a magic string into output files we could look for?
This becomes especially tricky in certain other situations: for example, you could imagine wanting to legitimately transpile code twice for various reasons, e.g. chaining plugins together.
The key here is to make things as painless as possible for end users by default, and give them ways to override the defaults tastefully.
I'm not sure what a good solution is yet, but we should think carefully before shipping changes related to this. Parcel is getting picked up across the world now, and our decision here will affect everyone later. The worst situation to end up in is to ship a quick fix and then realize later that it's a bad approach, since users will upgrade their parcel and discover their codebase breaks on the new version. Problems like that can doom traction, and parcel has a lot of momentum now.
A dumb solution would be to just try a stock babel fallback config if we get an unknown plugin error. That should transpile transpiled code just fine. But I'm skeptical that's a good idea.
Another idea is to add a .parcelignore file, so that users can add individual .babelrc paths that should be ignored. But that just punts the problem to users.
Can anyone think of a default behavior that works in all cases but doesn't produce unexpected or hidden side effects?
|
Even if we can determine whether or not the library has been transpiled, it may not be desirable to simply apply the transforms described in said library's babel config. Aside from the clear problem of conflicting babel versions and missing babel plugins, there's other things to consider. For example, let's say parcel can detect transpiled code and conditionally run transforms if the code isn't transpiled. I'm building a package that pulls in package X which parcel knows has not been transpiled, but the babel config for this package only transpiles code to ES2015 (ES6). I want my code to support the ES5 spec - so this solution won't suffice. There appears to be a solution for the above issue with webpack, via https://github.com/andersdjohnson/webpack-babel-env-deps (which I discovered through the discussion at babel/babel-loader#171); so perhaps we can take some ideas from there. |
IMO it is fundamentally wrong to try to respect |
My comments from twitter:
|
To elaborate:
I think we should go for a two pronged approach:
In any case, we need a lot more community feedback on how do implement this, along with support from other bundlers, before we jump into this. I don't want to come up with something Parcel specific here. |
I understand the reasons behind both positions (transpiling or not) and I like this ⬆️, trying to come with a "standard" across all npm modules. That said, this will likely take a lot of time to achieve something decent and in the meantime refrain people from using parcel broadly because packages they're using with their current setup (webpack) can't be used with parcel. Do you think coming up with a temporary workaround (a |
@jsiebern if the babel config is in the |
Ok merged #559, which disables |
This is great. I was thinking, maybe a general For some reason, libraries don't seem to care that they're publishing broken modules as long as their Got mixed feelings about this though, since in cases like these its absolutely clear that the library is broken and parcel is helpful pointing that out. Unfortunately app developers are the ones getting the helpful info, not library developers. Maybe a parcel-sponsored linter that detects common issues and that library users could drop into their project would be helpful? A "ready-for-the-future" linter that e.g. detects incorrectly written es6 modules among other things. |
I generally agree with everyone mentioning that |
Is this fixed ? i think im going to have to go back to webpack |
@prependto It has been fixed and released with v1.6 |
It's fixed, but now the problem is how to force babel compilation for modules that need to be compiled. For example, it's common for monorepo to symlink source packages to node_modules (#948). |
Just opened #1101 which adds support for a |
Closing since #1101 is merged. |
Is there going to be support for non-linked modules? i.e. transpiling from |
I came here after #1128 In here we're using react-map-gl (which uses mapbox-gl), and we're getting a runtime error
Which apparently comes - from what I understood - when I'm posting here, because everyone seems to be saying that
I'm clearly encountering that issue because one of those 2 packages is transpiled... I'm very lost here... they aren't supposed to be built, but they are, apparently. Some additional infos :
What is the truth ? Are they supposed to be transpiled or not ? Why ? Thanks for your help... |
Hey! Coming here after spending half a day in frustration. I'm reasonably certain I know what the problem is, but not how to solve it. Right now, I have a dependency (https://github.com/yahoo/react-dnd-touch-backend/) that publishes its own I can wait for the library author to unpublish |
Just wanted to update comment here and note that the upstream package maintainer did remove |
Based on twitter convo:
https://twitter.com/dan_abramov/status/938090483166924800
The text was updated successfully, but these errors were encountered: