[parcel 2] Private class fields compile successfully when used in modules but not otherwise
See original GitHub issue🐛 bug report
Source files containing classes with private methods fail to build unless:
a) .babelrc contains "plugins": ["@parcel/babel-plugin-transform-runtime", "@babel/plugin-proposal-class-properties", "@babel/plugin-proposal-private-methods"]
b) the file is imported from another module
🎛 Configuration (.babelrc, package.json, cli command)
Please see attached .zip file
🤔 Expected Behavior
In my opinion, the code should compile and work.
WHO DOES IT HELP, to need to specify explicitly that they want their code compiled and not see an error message?
I even googled and only found that the first plugin needs to be specified. I only figured the second one out when I tried babel’s reproduction editor, unchecked “shipped proposals”, and it complained that I needed it.
The code works in chrome, so why should I need an extra flag just to make parcel make it work in chrome?
😯 Current Behavior
It is inconsistent. Works on modules, not on not modules where it shows this:
$ npm run build
> build
> parcel build src/main.ts --log-level verbose --detailed-report 100 --target modern
🚨 Build failed.
@parcel/transformer-babel: Support for the experimental syntax 'classPrivateProperties' isn't currently enabled (3:3):
SyntaxError: Support for the experimental syntax 'classPrivateProperties' isn't currently enabled (3:3):
at Object._raise (/private/tmp/parcel-cache-bug/repro_main/node_modules/@babel/parser/lib/index.js:748:17)
at Object.raiseWithData (/private/tmp/parcel-cache-bug/repro_main/node_modules/@babel/parser/lib/index.js:741:17)
at Object.expectOnePlugin (/private/tmp/parcel-cache-bug/repro_main/node_modules/@babel/parser/lib/index.js:9116:18)
at Object.parseMaybePrivateName (/private/tmp/parcel-cache-bug/repro_main/node_modules/@babel/parser/lib/index.js:10633:12)
at Object.parsePropertyName (/private/tmp/parcel-cache-bug/repro_main/node_modules/@babel/parser/lib/index.js:11130:155)
at Object.parseClassElementName (/private/tmp/parcel-cache-bug/repro_main/node_modules/@babel/parser/lib/index.js:12644:22)
at Object.parseClassMemberWithIsStatic (/private/tmp/parcel-cache-bug/repro_main/node_modules/@babel/parser/lib/index.js:12562:22)
at Object.parseClassMemberWithIsStatic (/private/tmp/parcel-cache-bug/repro_main/node_modules/@babel/parser/lib/index.js:6856:11)
at Object.parseClassMember (/private/tmp/parcel-cache-bug/repro_main/node_modules/@babel/parser/lib/index.js:12532:10)
at callParseClassMember (/private/tmp/parcel-cache-bug/repro_main/node_modules/@babel/parser/lib/index.js:6820:13)
/private/tmp/parcel-cache-bug/repro_main/src/file.ts:3:2
2 | export class Test {
> 3 | #dialog(text){
> | ^
4 | alert(text);
5 | }
npm ERR! code 1
npm ERR! path /private/tmp/parcel-cache-bug/repro_main
npm ERR! command failed
npm ERR! command sh -c parcel build src/main.ts --log-level verbose --detailed-report 100 --target modern
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/daniel/.npm/_logs/2021-01-25T18_43_53_565Z-debug.log
But when importing the file containing the class from another module:
$ npm run build
> build
> parcel build src/main.ts --log-level verbose --detailed-report 100 --target modern
✨ Built in 732ms
dist/modern.js 303 B 97ms
├── ../mymodule/file.js 184 B 62ms
├── Code from unknown sourcefiles 80 B 0ms
└── src/main.ts
💁 Possible Solution
It needs to decided if classes with private properties should work out of the box or not and then either the error message needs to also be shown when importing from a module or the bug preventing it from work in not a module needs to be fixed.
🔦 Context
I tried to write a class and it didn’t compile, but a class in a module which I had previously written did.
💻 Code Sample
To use this you need to run npm install in both repro_main and mymodule. Then you cd into repro_main and run npm run build. Then you open the file and switch one of the two lines which are commented out and then you run it again.
🌍 Your Environment
| Software | Version(s) |
|---|---|
| Parcel | 2.0.0-nightly.551+6d9e3901 |
| Node | v15.6.0 |
| npm/Yarn | 7.4.0 |
| Operating System | macOS High Sierra 10.13.6 |
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (2 by maintainers)

Top Related StackOverflow Question
Weird those files were not showing up for me at first
test-20210404T090822Z-001.zip The included package.json is with
2.0.0-beta.2, and it won’t build usingstart-webscript. However, if you downgrade to2.0.0-beta.1, it will build.@mischnic Please let me know if you can reproduce it on your end using the zip file above or not.