webpack
webpack copied to clipboard
Automatic publicPath selection fails due to additional external script
Bug report
What is the current behavior?
If the publicPath value (under output) is not set in the Webpack config, Webpack calls the AutoPublicPathRuntimeModule (link) to find the current path by looking at the last included script file. This works if the last script file is [a] not an inline script and [b] part of the webpack output and therefore the src attribute is a reasonable reference to the intended public path.
If neither of those criteria is matched, e.g. a script added by Google Tag Manager, the AutoPublicPathRuntimeModule cannot find the current path, and throws the following error:
Automatic publicPath is not supported in this browser
The red rectangle on the screenshot below highlights an example of an external script added to the end of the script list. It is added by Google Tag Manager on Linux devices only and results in the error described above.
On Windows and macOS, this Google Tag Manager script is not added and the last script is main.5dd691d8552e0c47.js. This script is then selected by the AutoPublicPathRuntimeModule to find the current path, and works without issues.
If the current behavior is a bug, please provide the steps to reproduce.
See above.
What is the expected behavior?
While it can be solved by setting the publicPath value in the Webpack config file, the AutoPublicPathRuntimeModule should not use the last script to find the current path, as this is prone to errors caused by other packages adding additional external scripts.
If that is not possible, the logged error message (Automatic publicPath is not supported in this browser) could be improved, as it is supported in this browser, but obstructed by a script added by a different package.
Other relevant information: webpack version: 5.64.0 Node.js version: v16.11.1 Operating System: Linux (issue), Windows (no issue), MacOS (no issue) Additional tools: Chrome (V103), Firefox
It is fallback for old browsers... Can you provide value of RuntimeGlobals.global, but yes, we can improve this
hm.. strange in your example for main.js should be document.currentScript.src, but yes else case could be improved..
It should use import.meta.url. Maybe you forgot to set the script type to module in webpack config, as you are using script tags with type="module"?
This issue had no activity for at least three months.
It's subject to automatic issue closing if there is no activity in the next 15 days.
bump
Issue was closed because of inactivity.
If you think this is still a valid issue, please file a new issue with additional information.