Skip to content

Fix webpack browser install - #1844

Closed
stevemk14ebr wants to merge 6 commits into
handlebars-lang:masterfrom
stevemk14ebr:master
Closed

stevemk14ebr wants to merge 6 commits into
handlebars-lang:masterfrom
stevemk14ebr:master

Conversation

@stevemk14ebr

@stevemk14ebr stevemk14ebr commented Mar 23, 2022 •

Copy link
Copy Markdown

Fixes #1174

In webpack 5 things seem to have changed. From webpack/webpack#15007 which itself is from react/create-react-app#11756 the fs polyfills webpack used to include by default are no longer included. The browser wildcard '.' isn't valid according to webpack/webpack#15007 and should refer to a full filepath. I've changed the config to be valid, and it seems to work as far as I can tell. There was also a missing coffeescript dev dependency which caused the grunt build to fail, I added this too.

@stevemk14ebr stevemk14ebr changed the title Fix https://github.com/handlebars-lang/handlebars.js/issues/1174 Fix webpack browser install Mar 23, 2022

@jaylinski jaylinski left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this should be backported to the 4.x branch as soon as merged.

Comment thread package.json Outdated
"webpack": "^1.12.6",
"webpack-dev-server": "^1.12.1"
"webpack-dev-server": "^1.12.1",
"coffeescript": "^2.6.1",

@jaylinski jaylinski Mar 23, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add coffeescript as a dependency? The build doesn't seem to fail...

Please provide the error output.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 ~/source/repos/tmp/aster/node_modules/handlebars  npm run build

> handlebars@5.0.0-alpha.1 build
> grunt build

Loading "bg-shell.coffee" tasks...ERROR
>> Error: Grunt attempted to load a .coffee file but CoffeeScript was not installed.
>> Please run `npm install --dev coffeescript` to enable loading CoffeeScript.
Loading "child-process.coffee" tasks...ERROR
>> Error: Grunt attempted to load a .coffee file but CoffeeScript was not installed.
>> Please run `npm install --dev coffeescript` to enable loading CoffeeScript.

Running "babel:cjs" (babel) task

Running "webpack:handlebars" (webpack) task
Version: webpack 1.15.0
        Asset    Size  Chunks             Chunk Names
handlebars.js  572 kB       0  [emitted]  main

Running "webpack:runtime" (webpack) task
Version: webpack 1.15.0
                Asset    Size  Chunks             Chunk Names
handlebars.runtime.js  383 kB       0  [emitted]  main

Done.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the dependency so this can move forward. I'm probably doing something wrong, but that's the error I received, and why I added it. Works without errors with coffeescript.

@stevemk14ebr

stevemk14ebr commented Mar 23, 2022 •

Copy link
Copy Markdown
Author

the big diff from that is just from json formatting ^

@chrisl777

Copy link
Copy Markdown

@stevemk14ebr @jaylinski Any update on this PR? I am hoping to be able to use handlebars with create-react-app (webpack 5 under the hood, presumably).

@jaylinski jaylinski added this to the 4.8.0 milestone May 12, 2022
@jaylinski

Copy link
Copy Markdown
Member

I'll have a look at it this weekend.

@jaylinski jaylinski self-assigned this May 12, 2022
jaylinski added a commit that referenced this pull request 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 mentioned this pull request May 15, 2022
1 task done
@jaylinski

Copy link
Copy Markdown
Member

I added a test for this bug and opened a new PR: #1862

I'll merge and tag it (hopefully) next week.

jaylinski added a commit that referenced this pull request 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
@chrisl777

Copy link
Copy Markdown

@jaylinski Awesome, thank you!

jaylinski added a commit that referenced this pull request May 17, 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 added a commit that referenced this pull request May 17, 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 added a commit that referenced this pull request May 17, 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
@stevemk14ebr

Copy link
Copy Markdown
Author

Bump on doing a release on npm?

@jaylinski

jaylinski commented Aug 1, 2023 •

Copy link
Copy Markdown
Member

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

zeekay pushed a commit to hanzoai/handlebars.js that referenced this pull request Sep 9, 2026
As explained in issue handlebars-lang#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 handlebars-lang#1174
Closes handlebars-lang#1844
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

3 participants