shellscape / koa-webpack

Development and Hot Reload Middleware for Koa2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: how to use with lerna/yarn workspaces monorepo

hedefalk opened this issue · comments

Sorry to post as issue here since this is just a question…

I'm having issues since splitting up my monolith to modules using yarn workspaces in a monorepo.

What I have is a web package that is just the webpack build and then a separate koa server package that exposes the result of that. For production build everything's fine, but for the dev server I'm having problems with runtime dependencies of the webpack build.

When running the dev server it's trying to resolve babel-loader from within the koa server project:

[server] ERROR in multi @babel/polyfill ../web/src/marko/marko-bootstrap ../web/src/materialize/kb-materialize.scss
[server] Module not found: Error: Can't resolve 'babel-loader' in '/Users/viktor/dev/projects/kb-frontend/packages/server'
[server]  @ multi @babel/polyfill ../web/src/marko/marko-bootstrap ../web/src/materialize/kb-materialize.scss main[1]
[server]
[server] ERROR in multi webpack-hot-client/client?c70c9a83-bcc9-4b04-996f-2574026e7876 @babel/polyfill ../web/src/marko/marko-bootstrap ../web/src/materialize/kb-materialize.scss
[server] Module not found: Error: Can't resolve 'babel-loader' in '/Users/viktor/dev/projects/kb-frontend/packages/server'
[server]  @ multi webpack-hot-client/client?c70c9a83-bcc9-4b04-996f-2574026e7876 @babel/polyfill ../web/src/marko/marko-bootstrap ../web/src/materialize/kb-materialize.scss main[2]

Being lazy for the moment I just added it as a dev dependency on the koa project but then I get follow ups for everything else:

Error: Cannot find module '@babel/plugin-proposal-export-namespace-from

If I add that I instead get the next one and so forth:

Error: [BABEL] /Users/viktor/dev/projects/kb-frontend/packages/web/src/marko/marko-bootstrap.js: Could not find plugin "proposal-numeric-separator". Ensure there is an entry in ./available-plugins.js for it. (While processing: "/Users/viktor/dev/projects/kb-frontend/node_modules/@babel/preset-env/lib/index.js")

Am I consuming this wrong when I do something like this:

import devWebpackCompiler from '@kb-front/web' // the web package
const webpackMiddleware = await koaWebpack({ compiler: devWebpackCompiler })
app.use(webpackMiddleware)

where the webpack compiler is created and exported in the web package:

const webpack = require('webpack')
const devConfig = require('./webpack.dev.js')
const compiler = webpack(devConfig)
module.exports = compiler

Thanks!

Sorry, realize this has nothing to do with this project since I get the same with webpack-dev-server and webpack-hot-client natively too.

I also get the same error even if I create the middleware in the web project too. So something about how deps are resolved at runtime is not working as I would have wanted it to.