question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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

parcel-class-bug.zip

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:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ProLosercommented, Jan 26, 2021

Weird those files were not showing up for me at first

0reactions
calvintam236commented, Apr 5, 2021

Please provide a reproduction

test-20210404T090822Z-001.zip The included package.json is with 2.0.0-beta.2, and it won’t build using start-web script. However, if you downgrade to 2.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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Private fields not compiling with Webpack - Stack Overflow
Luckily, babel and webpack work well together, so to get ESNext features, you will want to include the babelLoader.
Read more >
A study of the Parcelize feature from Kotlin Android Extensions
For non-final classes or interfaces, the Parcelize plugin will generate a call to Parcel.writeParcelable() instead. Classes are final by default in Kotlin, ...
Read more >
arcgis.features.managers module | ArcGIS API for Python
Helper classes for managing feature layers and datasets. These class are not created by users directly. Instances of this class, are available as...
Read more >
Minimum Standards for Child-Care Centers
certificate upon successful completion of the training. The certificate is not required to use the term "lifeguard," but the permit holder ...
Read more >
Banner Basics and Navigation - Staff
It is recommended that when using a form with multiple fields, use the Tab key to move ... All SLCC Banner forms are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found