Skip to content
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

Fix bundler issue with webpack 5 #1862

Merged
merged 1 commit into from
May 17, 2022
Merged

Fix bundler issue with webpack 5 #1862

merged 1 commit into from
May 17, 2022

Conversation

jaylinski
Copy link
Member

@jaylinski jaylinski commented 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

  • 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
Copy link

il421 commented Oct 3, 2022

has this fix been released?

@joeskeen
Copy link

joeskeen commented Oct 4, 2022

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

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
Member Author

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

@fatwong
Copy link

fatwong commented Feb 3, 2023

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

@karlo-humanmanaged
Copy link

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
Copy link

khoait commented Mar 28, 2023

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
Copy link

nzayatz14 commented Jun 12, 2023

@jaylinski Any updates on this?

@williameliasson-dev
Copy link

@jaylinski update plz

@jaylinski
Copy link
Member Author

jaylinski commented Aug 1, 2023

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