[Bug] Workspace 1 uses different webpack instance than an imported Workspace 2
See original GitHub issue- I’d be willing to implement a fix
Describe the bug
We have a weird setup where one package builds subpackages using the subpackages’ webpack configurations. This worked before Yarn 2, and I’m trying to get it to work with Yarn 2. The problem is that the subpackage’s webpack
instance is a different instance than the first package’s webpack
instance (due to different virtual paths), which errors with The 'compilation' argument must be an instance of Compilation
.
I’d expect this to work, since both packages have the same version of webpack
specified. But if this is intended behavior, is there a way to get this working? Maybe worth adding to the docs in case others have a similar problem.
To Reproduce
Reproduction
const { promises: { writeFile } } = require('fs')
await packageJson({
name: 'package2',
devDependencies: {
'webpack': '^5',
// changes virtual path between package1/package2
'webpack-cli': '*',
},
}, { cwd: 'package2/' })
await writeFile('package2/webpack.config.js', `
const path = require('path')
const webpack = require('webpack')
module.exports = {
entry: path.resolve(__dirname, 'index.js'),
// configure a plugin using this webpack's instance
plugins: [new webpack.HotModuleReplacementPlugin()],
}
`)
await packageJson({
name: 'package1',
devDependencies: {
'webpack': '^5',
'package2': 'workspace:*'
},
}, { cwd: 'package1/' })
await writeFile('package1/buildSubpackage.js', `
const webpack = require('webpack')
const config = require('package2/webpack.config.js')
webpack(config, (err, stats) => {
if (err) {
console.error(err);
process.exit(1);
}
console.log(stats.toString());
})
`)
await packageJson({
name: 'root',
private: true,
workspaces: [
'package1/',
'package2/',
],
})
await yarn('install')
await expect(yarn('workspace', 'package1', 'node', 'buildSubpackage')).rejects.not.toThrow()
Screenshots
If applicable, add screenshots to help explain your problem.
Environment if relevant (please complete the following information):
- OS: [e.g. OSX, Linux, Windows, …]
- Node version [e.g. 8.15.0, 10.15.1, …]
- Yarn version [e.g. 2.4.0, …]
Additional context
Add any other context about the problem here.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
This issue reproduces on master:
Thanks! Got past the error