-
Notifications
You must be signed in to change notification settings - Fork 2k
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
global is not defined in each.js #1593
Comments
That's strange because there was no problem with the build and the tests. Who is showing this error measure? You IDE? Eslint? |
The bug is in the Google Chrome Console when the context is an object. When i remove the "global." property it works correct (jumps into the else statement) and the template shows the correct values, without the ReferenceError. |
Could you describe exactly, what you are doing? Which file are you looking at (which URL)? In the built handlebar.js file, the each helper is wrapped with a function by Webpack, which defines "global" as a parameter". I cannot reproduce your issue anywhere. |
Found the issue in our webpack.config. Changed the property "node: false" to "node: {global: true}". Thank you for your help! |
I'm having this same issue. The specs define handlebars.js/spec/env/common.js Line 1 in 0c8230c
which is why this doesn't cause any issues in the tests. Is it expected that we should have to always define |
OK, the change was made when #1557 was merged. So, this is a regression. As you say, there wasn't a test to catch this problem and I hadn't seen this coming when I merged the PR. If you have a suggestion on how to solve this and you are willing to open a PR, go ahead. I think there should be 3 steps in a PR:
|
Thanks so much for reopening this. Let me see if I can allocate some time to work on a PR, however I'm not 100% sure I'll have that leeway. I'll have to dig in deeper to figure out exactly what the check is doing, but if it's just to determine if If anyone else needs a workaround in the meantime this workaround is working for me: My use case is a webpack 4 config with By adding |
After about a day of trying to figure out a good way to test this, I'm not really sure how to proceed. The way to trigger this issue appears to be: precompile a template and include the CJS handlebars runtime via webpack, then run the resulting JS code in a browser where I can't figure out a great way to write an integration test that requires webpack compile the code then run the js via selenium or some such. Any ideas? |
@kjg You sounded like you already have a setup that reproduces the error. I thought you could use that to derive a minimal project ( |
Here is a branch with a minimal test case. Once built, the html file needs to be opened in a browser to see the error. I don't have a way to get this to actually fail the CI build yet since it requires running in a browser. |
Maybe jsdom will do the trick... Probably won't because "global" is also present. |
Maybe #1688 is the solution to address this in a test-case. Since the tests already run in Saucelabs, it should fail in the browsers. Unfortunately, the Internet-Explorere Saucelabs tests are not working at the moment, so the tests will fail anyway. |
I spend a long time trying to get this to fail in the browser tests. Removing global from spec/env/common.js is a good step. However from what I've found all the browser tests rely on dist/handlebars.js or dist/handlebars.runtime.js The way these files are built via webpack seems to handle defining Maybe it could be argued that this is a bug in the way webpack treats a target of This certainly seems to be a pretty narrow edge case. However since handlebars doesn't make extensive use of 'global' other than this one check, maybe it would still be okay to for us to fix it here? |
It might also be enough to forbid the global "global" in the linting rules. |
I opened a PR to fix this issue: #1692 Would be nice if someone could take a look at it. |
we have this problem and now using this workarounds (ensuring new webpack.DefinePlugin({
global : undefined,
'global.Symbol' : 'Symbol', // workarounds https://github.com/handlebars-lang/handlebars.js/issues/1593
}), |
the vitejs solution is import { defineConfig } from 'vite';
export default defineConfig({
define: {
global: {},
},
}); |
If `global` is used and handlebars is compiled for browser usage without a Node.js `global` polyfill, handlebars fails with a `global is undefined` error. Fixes #1593
If `global` is used and handlebars is compiled for browser usage without a Node.js `global` polyfill, handlebars fails with a `global is undefined` error. Fixes #1593
I released a new patch version (v4.7.8) on npm. Sorry it took so long. |
After the version 4.1.2 there is an error in the each.js helper file.
The text was updated successfully, but these errors were encountered: