Skip to content

Fix bundler issue with webpack 5 - #1862

Merged
jaylinski merged 1 commit into
masterfrom
bugfix-1844
May 17, 2022
Merged

jaylinski merged 1 commit into
masterfrom
bugfix-1844

Conversation

@jaylinski

@jaylinski jaylinski commented May 15, 2022 •

Copy link
Copy Markdown
Member

As explained in issue #1844 and in issue
webpack/webpack#15007 (comment),
the way we used the browser-field was wrong.

The main reason for using the browser-field is the requirement of
require('fs') in the main-entry-file.
The workaround for this was using require('handlebars/lib/handlebars'),
but now it will also work via require('handlebars') for bundlers that
respect the browser-field.

The "./runtime"-config was removed, because it didn't have any effect.
In order to detect regressions, the webpack-integration test was
extended to test with different webpack versions.

Fixes #1174
Closes #1844

  • Backport to 4.x as soon as merged

@jaylinski jaylinski self-assigned this May 15, 2022
@jaylinski jaylinski added this to the 4.8.0 milestone May 15, 2022
As explained in issue #1844 and in issue
webpack/webpack#15007 (comment),
the way we used the `browser`-field was wrong.

The main reason for using the `browser`-field is the requirement of
`require('fs')` in the main-entry-file.
The workaround for this was using `require('handlebars/lib/handlebars')`,
but now it will also work via `require('handlebars')` for bundlers that
respect the `browser`-field.

The `"./runtime"`-config was removed, because it didn't have any effect.
In order to detect regressions, the webpack-integration test was
extended to test with different webpack versions.

Fixes #1174
Closes #1844
@jaylinski
jaylinski merged commit 9bff03f into master May 17, 2022
@jaylinski
jaylinski deleted the bugfix-1844 branch May 17, 2022 18:46
@jaylinski jaylinski mentioned this pull request May 17, 2022
@il421

il421 commented Oct 3, 2022

Copy link
Copy Markdown

has this fix been released?

@joeskeen

joeskeen commented Oct 4, 2022 •

Copy link
Copy Markdown

The workaround for this was using require('handlebars/lib/handlebars'),

I've tried doing that, but it just exposes a new error:

node_modules/handlebars/lib/handlebars/internal/proto-access.js:48:4-14 - Error: export 'log' (imported as 'logger') was not found in '../logger' (possible exports: default)

Will this fix be released soon? I see on npmjs.com that the last release was 2 years ago?

@sethreidnz

Copy link
Copy Markdown

Do we know when this might be released to NPM? This is blocking my project from upgrading to latest create react app...

@jaylinski

Copy link
Copy Markdown
Member Author

I'll try to get it done this week. 🤞

@fatwong

fatwong commented Feb 3, 2023

Copy link
Copy Markdown

May I ask when will this be released? it's already 2023

@karlo-humanmanaged

Copy link
Copy Markdown

I hope this gets merged soon.

For those having issues doing this workaround in Typescript, Here's what I did:

create a type definition file:

declare module "handlebars/lib/handlebars" {
  // Re-export the types from the existing handlebars module
  export * from "handlebars";
}

imports will be like this:

import Handlebars from "handlebars/lib/handlebars";

usage is:

const template = Handlebars["export="].compile(textTemplate);
...

@khoait

khoait commented Mar 28, 2023

Copy link
Copy Markdown

Glad that this is merged. I hope this fix will be released soon.

@karlo-humanmanaged I got Typescript complaining from your workaround:

Module '"handlebars"' uses 'export =' and cannot be used with 'export *'.ts(2498)

Here's mine:

Create a type definition file types/handlebars.ts:

declare module "handlebars/lib/handlebars" {
  // Re-export the types from the existing handlebars module
  import Handlebars = require("handlebars");
  export default Handlebars;
}

Import like this:

import Handlebars from "handlebars/lib/handlebars";

Usage:

const template = Handlebars.compile(textTemplate);

@nzayatz14

nzayatz14 commented Jun 12, 2023 •

Copy link
Copy Markdown

@jaylinski Any updates on this?

@williameliasson-dev

Copy link
Copy Markdown

@jaylinski update plz

@jaylinski

jaylinski commented Aug 1, 2023 •

Copy link
Copy Markdown
Member Author

I released a new patch version (v4.7.8) on npm. Sorry it took so long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

webpack + require handlebars error

9 participants