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 webpack browser install #1844

Closed
wants to merge 6 commits into from

Conversation

stevemk14ebr
Copy link

@stevemk14ebr stevemk14ebr commented Mar 23, 2022

Fixes #1174

In webpack 5 things seem to have changed. From webpack/webpack#15007 which itself is from facebook/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
Copy link
Member

@jaylinski jaylinski left a comment

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.

package.json Outdated
@@ -70,12 +70,13 @@
"uglify-js": "^3.1.4",
"underscore": "^1.5.1",
"webpack": "^1.12.6",
"webpack-dev-server": "^1.12.1"
"webpack-dev-server": "^1.12.1",
"coffeescript": "^2.6.1",
Copy link
Member

@jaylinski jaylinski Mar 23, 2022

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

> [email protected] 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
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
Copy link
Author

stevemk14ebr commented Mar 23, 2022

the big diff from that is just from json formatting ^

@chrisl777
Copy link

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

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

Bump on doing a release on npm?

@jaylinski
Copy link
Member

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
3 participants