parcel: š Can't add more presets to .babelrc (Merge defaults with babelrc file problem)
From 1.5.1 to 1.62 I cannot get rid of āMissing class properties transformā when using stage-2 preset. It seems that under some situations the babelrc gets ignored (or that āenvā, āreactā presets are locked)
š Configuration (.babelrc, package.json, cli command)
I am using --no-cache
all the time so deleting the cache is not an applicable workaround for my case.
babel
{
"presets": ["env", "react", "stage-2"]
}
package
{
"name": "ui",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"start": "parcel src/index.html --no-cache",
"build": "parcel build src/index.html --no-cache"
},
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-redux": "^5.0.7",
"react-router-dom": "^4.2.2"
},
"devDependencies": {
"babel-preset-env": "^1.6.1",///with or without it
"babel-preset-react": "^6.24.1",///with or without it
"babel-preset-stage-2": "^6.24.1",
"parcel-bundler": "^1.6.2"
}
}
š¤ Expected Behavior
Babel should respect my babel config and include all the transformations that this preset should add.
šÆ Current Behavior
Babel seems to ignore my config and still errors with āMissing class propertiesā
š Possible Solution
I tried to read the codebase, but i donāt know it too well. However I suspect it related to a pkg constructor param which seems to block the reading of the babel file under some circusntamces.
š¦ Context
I just want to use transform class properties syntax
š» Code Sample
import React from 'react'
class Root extends React.Component {
state = { time: 0 }//errors here
render() {
return 'hi from react ' + this.state
}
}
export default Root
š Your Environment
Software | Version(s) |
---|---|
Parcel | from 1.5.1 to 1.6.2 |
Node | 8.9.2 |
npm/Yarn | 1.2.1 |
Operating System | windows 10 (and ubuntu 16.04 only parcel 1.6.2) |
I think this is related to https://github.com/parcel-bundler/parcel/issues/824 and https://github.com/parcel-bundler/parcel/issues/824
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 4
- Comments: 25 (8 by maintainers)
Iāve run into the same problem with
.babelrc
:and compiled success after adding
"plugins": ["transform-class-properties"]
.babelrc
:Parcel 2 will no longer merge
.babelrc
with a default config for babel-preset-env. Instead,.babelrc
will override the default config.Commenting certain part of the code it is not working for me anymore⦠This bug should be top priority to be solved it is very annoying š¦ (canāt do react without transform class properties)
any workaround for now?
Unfortunately none of the .babelrc examples here seem to work for me (even when playing with the order).
["env", "react"]
alone wonāt work, as the codebase uses the spread operator extensively (and then that fails because of that). If I add that plugin manually, I still get an error, with the .bablerc looking like the following:I guess the class property thing might actually work for my own codebase (Iām not sure in the processing order of parcel though to be sure), but it definitely fails for dependencies. I get the following error in react-redux-toastr:
I get the following error with both āstage-xā or manually adding ātransform-class-propertiesā. (and as I mentioned, the same project setup works with babel-jest and webpack)
This works for me.
@devongovett I think this is because the order of plugins and presets matters:
This:
means that
stage-2
will be applied first and afterwardsenv
.Plugins run before presets (https://babeljs.io/docs/plugins/#pluginpreset-ordering), so
will first run
transform-class-properties
, thenstage-2
and thenenv
.But I think the way that parcel modifies the config (translating
env
into the individual plugins - why are we even doing that, avoiding a new dependency in the project itself?) breaks that order:will behave the same as
which isnāt what we want? (
env
is somehow always the first entry). Iām guessing, that the error stems from someenv
plugin, which canāt handle static class properties.Commenting out only https://github.com/parcel-bundler/parcel/blob/eaf51d01462b353aeaf78ebe80d797477ae1938d/src/transforms/babel.js#L114 fixes the error (but of course no
env
plugins are applied because"plugins": [/*all the indivial plugins from "env"*/]
isnāt added to the config).EDIT: Specifying the plugin explicitly works because it will be the first plugin listed
and
Plugin ordering is first to last.
There is some logic here which filters out presets already applied by babel-preset-env. stage-X presets are not in the list though, so Iām a not exactly sure whatās going on. Thatās the place to look though, if someone wants to take this on.
https://github.com/parcel-bundler/parcel/blob/0d9d14cbda742e612b36f5c37db55e45a7a1ff1e/src/transforms/babel.js#L98-L103
Have a similar issue with spread operator in a node module:
Babel preset is installed and working fine with object spreading in the project code. Any suggestions here?
Iāve run into the same problem when using
parcel-bundler
withbabel-preset-react-app
.package.json
:.babelrc
:Getting
Missing class proper
error.@lrn2prgrm I think I was mistaken before, mixing up plugins and presets. If you want to give this a try:
.babelrc
Just be sure to actually install those plugins first.
Anyone manage to resolve this? I have the same issue with parcel 1.6.x. And adding the plugins manually changed nothing. The same babel conf seems to work for babel-jest and for webpack