webpack: [Webpack 5 bug, works in 4] exported library in an empty object
Bug report
What is the current behavior?
Exported library is an empty object.
If the current behavior is a bug, please provide the steps to reproduce.
// src/Main.tsx
export default { foo: 1 }
// webpack.config.js
const path = require('path')
module.exports = {
devtool: 'inline-source-map',
entry: {
Main: './src/Main.tsx',
},
output: {
filename: '[name]-[hash].js',
path: path.resolve(__dirname, 'dist'),
publicPath: 'http://0.0.0.0:8080/',
library: '[name]',
libraryExport: 'default',
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts'],
}
}
// in the web page
console.log('Main'); // --> {}
What is the expected behavior?
// in the web page, using Webpack 4.44.2 we get the expected:
console.log('Main'); // --> {foo: 1}
Other relevant information: webpack version: 5.3.2 Node.js version: 12.4.0 Operating System: OSX 10.15.7 Additional tools:
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 6
- Comments: 26 (7 by maintainers)
Please do not ignore
If the current behavior is a bug, please provide the steps to reproduce.
, for webpack-dev-server it is known issues, I will reopen if after you fix itWorks when updating to
"webpack-dev-server": "^4.0.0-beta.0"
When you change webpack-dev-server
3.x -> 4.x
, Don’t forget to replacepublicPath
withstatic
contentbase
was renamed tostatic: './public'
disablehostcheck
was renamed tofirewall: false
@sapolio put this in
package.json
(i.e.{ devDependencies: { "webpack-dev-server": "^4.0.0-beta.0" } }
)I test it on “webpack”: “^5.38.1”, “webpack-cli”: “^4.7.0”, “webpack-dev-server”: “4.0.0-beta.x” (0-3) it’s not works 😦
It’s working fine now
What is your entry point? What do you export from source code, and also your package.json please. I would also recommend to create minimal reproducible project like I did. Then it will be easier for you to understand the difference and for us to find an issue
Maybe this one would help: https://hinty.io/devforth/fix-webpack-imported-module-is-not-a-function-for-webpack5/
Didn’t try bundle file alone yet. OK I’ll make a repo a bit later.
What certain parts of setup do i need to expose? This is how it works on webpack@4 via DevServer.
The default export of main.js is an object literal.
And i see it in browsers window object as libraryName
Now i will reinstall webpack to version 5 and start it…
Now my libraryName is undefined. Then i comment out
libraryExport: 'default',
line. After that my libraryName becomes an empty object.