devtool source-map creates broken `webpack://` urls when `output.library.name` is an array containing a placeholder
See original GitHub issueBug report
What is the current behavior?
When using an output.library.name
containing a [name]
placeholder, e.g. ['MyLib', '[name]']
, the source maps generated by 'devtool': 'source-map'
are broken. I get a bunch of JS console warnings like this when using my scripts:
Source map error: Error: Invalid URL: webpack://MyLib.[name]/webpack/bootstrap
The problem seems to be that the [name]
placeholder in output.library.name
is being treated as literal in the source map URLs, rather than being filled in with the entry file name. Source maps aside, the JS does work as expected, with the placeholder being replaced in other contexts. As far as I can tell, this is a bug, as using the [name]
placeholder in output.library.name
is a supported feature.
If the current behavior is a bug, please provide the steps to reproduce.
- Create an empty folder. Add the following files:
webpack.config.js
:
const path = require('path')
module.exports = {
mode: 'production',
context: path.resolve(__dirname, 'src'),
entry: { foo: './foo.js' },
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name].js',
library: { name: ['MyLib', '[name]'], type: 'window' },
clean: true,
},
devtool: 'source-map',
module: {
rules: [{ test: /\.js$/u, use: ['babel-loader'] }],
},
cache: true,
}
package.json
:
{
"browserslist": "last 5 Chrome versions, last 3 Firefox versions, last 3 Safari versions, last 3 ChromeAndroid versions, last 2 Android versions, last 2 FirefoxAndroid versions",
"scripts": {
"build": "webpack"
},
"devDependencies": {
"@babel/core": "^7.16.0",
"@babel/preset-env": "^7.16.4",
"@babel/preset-react": "^7.16.0",
"babel-loader": "^8.2.3",
"prettier": "^2.5.1",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1"
}
}
babel.config.json
:
{ "presets": [["@babel/preset-env", { "spec": true }]] }
demo.html
:
<html>
<head>
<meta charset="utf-8" />
<script defer src="./build/foo.js"></script>
</head>
<body>Look at the JS dev console.</body>
</html>
src/foo.js
:
export function myThing() {
console.log('beep')
}
- Run
npm i && npm run build
. - Open
demo.html
. - Check the JS dev console.
What is the expected behavior?
The source maps should contain working webpack://
URLs with the [name]
placeholder filled in as expected.
Other relevant information: webpack version: 5.65.0 Node.js version: 16.13.1 Operating System: KDE Neon Linux
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (10 by maintainers)
Top GitHub Comments
@TrickyPi Be my guest! 👍
Okay