-
Notifications
You must be signed in to change notification settings - Fork 416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
External modules are not packaged with webpack 5 #651
Comments
Facing the same issue here. Downgrading webpack to 4.44.2 solves the issue for us. We were trying to upgrate to the above mentioned versions when we faced the issue. We also use Here's the config we use in the monorepo: const nodeExternals = require('webpack-node-externals');
const path = require('path');
const slsw = require('serverless-webpack');
const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
const babelConfig = require('./babel.config');
// Base webpack config. Other services can extend from it to bundle their
// lambdas.
module.exports = (dirName) => ({
entry: slsw.lib.entries,
target: 'node',
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
node: {
__dirname: true,
},
devtool: slsw.lib.webpack.isLocal ? 'nosources-source-map' : undefined,
externals: [
nodeExternals(),
nodeExternals({
modulesDir: path.resolve(dirName, '../../node_modules'),
}),
],
module: {
rules: [
{
loader: 'babel-loader',
test: /\.ts$/,
include: [
dirName,
path.resolve(dirName, '../../common'),
path.resolve(dirName, '../../config'),
],
exclude: /node_modules/,
options: {
presets: babelConfig.presets,
},
},
],
},
resolve: {
extensions: ['.ts', '.mjs', '.js'],
},
output: {
libraryTarget: 'commonjs2',
path: path.join(dirName, '.webpack'),
filename: '[name].js',
sourceMapFilename: '[file].map',
},
plugins: [
new webpack.EnvironmentPlugin({
// use 'development' unless process.env.NODE_ENV is defined
NODE_ENV: 'development',
}),
new CopyPlugin({
patterns: [
{ from: `${dirName}/src/assets`, to: 'src/assets' },
],
}),
],
}); |
I got the issue too. |
I got this issue too and found that all modules load with: const myModule = require('myModule') It works, but loading with import MyModule from 'myModule'; Does not. |
Facing the same issue, had to downgrade to Additional Data
|
I was able to work around this by disabling |
Thanks for sharing the workaround. I am wondering what's the reason behind it, and if it is the right solution or there is a better way of fixing the problem. |
@crespowang I guess this might have something to do with the issue: used here: serverless-webpack/lib/packExternalModules.js Lines 193 to 214 in 38135e4
|
I found that [email protected] packages node modules correctly. Beginning with [email protected], node modules are not packaged. |
Same issue related, as @maxholman mentions, this configuration :
work for me ! |
After added the concatenateModules: false option, there is another deprecation warning which is Module.issuer: Use new ModuleGraph API |
Also experiencing these issues, and the above workaround also does work. Might be worth pinning this issue so others know about the workaround until it's fixed. |
I had an issue where the workaround compiled but source maps were broken. Rolling back to webpack 4 was the only fix I could get to reliably work. |
@j0k3r Is there any chance to fix webpack 5 related issues? |
Opened a PR with the fix I've been using for a while. If anyone would like to help test it that'd be awesome, esp webpack4 backwards compat. |
Thanks @janicduplessis, I'll try on my webpack4 projects next week. |
One thing to note, using webpack5 and this workaround, result in a much larger app size
|
The workaround will not be needed anymore in the upcoming 5.4.1 release! So make sure not to forget to remove it :) |
5.4.1 was released yesterday: https://github.com/serverless-heaven/serverless-webpack/releases/tag/v5.4.1 |
Same problem, but neither the The code is working when compiled with Webpack 4. I reduced the code at its minimum:
Maybe the problem here comes from the weird use of Anyone has any clue? |
Same problem when using webpack 5.70.0 + webpack-dev-server 4.7.4 +
Did you find a solution/workaround @manelio ? |
anyone found solution or workaround for this? |
Same problem when using webpack 5.75.0. |
For anyone who still has this issue, please open up a new issue with a minimum reproduction repo so we can quickly nail down the cause. Thanks a lot. |
This is a Bug Report
Description
Since updating to the release version of webpack 5, it seems like external modules are no longer packaged. I investigated a bit and in
packExternalModules#getExternalModules
I don't see the externals I specify in my webpack config. I checked webpack 5 release notes but could not find a not about that and how to fix it. As a workaround I was able to usestats.compilation.modules
instead ofchunks
and it does include the externals. Not sure if this is a proper fix though.Similar or dependent issue(s):
N/A
Additional Data
The text was updated successfully, but these errors were encountered: