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
[BUG] Publisher Interface cannot be bunbled with Webpack 4 #23
Comments
Linked private support ticket: |
The Root CauseThe root cause is related to the version of acron used by Webpack 4 to parse the JavaScript. This version does not support certain JavaScript syntax. In the case of this particular error, it is setting public properties of classes. While you could fix this one error by changing this: export class PublisherInterface {
private child!: AsyncMethodReturns<ChiliWrapper>;
private chiliEventListenerCallbacks: Map<string, (targetId: string) => void> =
new Map<string, (targetId: string) => void>();
// eslint-disable-next-line @typescript-eslint/no-empty-function
private constructor() {
} to this: export class PublisherInterface {
private child!: AsyncMethodReturns<ChiliWrapper>;
private chiliEventListenerCallbacks: Map<string, (targetId: string) => void>;
// eslint-disable-next-line @typescript-eslint/no-empty-function
private constructor() {
this.chiliEventListenerCallbacks =
new Map<string, (targetId: string) => void>();
} Only more errors will be thrown by Webpack, because there were a number of "modern" JS syntax used in PublisherInterface. Reference webpack/webpack#10216, to see issue on Webpack github. |
Immediate Solutions for UsersWebpack 5Obviously the easiest solution is to use Webpack 5, which is using acorn version 8.x OverrideIf you must stay on Webpack 4 you can use overrides. If using npm, you can use overrides in your package.json "overrides": {
"acorn": "8.8.1"
} If using yarn, you can use resolutions in your package.json "resolutions": {
"acorn": "8.8.1"
} Potential Solutions from Publisher InterfaceIf we decide to support Webpack 4, then we will need to either change our code manually or have parcel run it through babel or tsc to remove any modern JS. I know the manual update of the code would work, but I do not think that is a practical idea - its 2022, this is the reason why all these libraries exists: so we don't have to use JS from the 2000s. The running of typescript through tsc or babel is possible, but not tested. I have tested running tsc alone, which indeed works. So in theory this should work. However, there is no consensuses if Webpack 4 should be supported, especially when the fixes for users are very straight forward and it appear the Webpack team no longer support version 4. (Also, Webpack 4 does not work one Node 18 do to changes in standard node library.) |
Describe the bug
When trying to bundle a project that has @chili-publish/publisher-interface with Webpack 4.x you receive an error message:
If you bundle with Webpack 5.1.0 or higher, you receive no error message
To Reproduce
Steps to reproduce the behavior:
npm run build
and see errorThe only reason we update webpack-cli too, is because the older CLI version does not work with 5.
4.Run
npm run build
and see no errorSolution
Use Webpack 5 (or other bundler like Parcel, Vite, etc) for you bundling needs.
The text was updated successfully, but these errors were encountered: