-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
vuejs/vue-ssr-webpack-plugin and webpack 5 #11718
Comments
I am facing same issue when updated to webpack 5 today. My current versions are"webpack": "5.0.0-rc.6", "vue-server-renderer": "2.6.10". |
yep.... problem not quit, i use |
I am facing the same problem. What I found out is that it seem like in webpack 5 var validate = function (compiler) {
if (compiler.options.target !== 'node') {
warn('webpack config `target` should be "node".');
}
- if (compiler.options.output && compiler.options.output.libraryTarget !== 'commonjs2') {
+ if (compiler.options.output && compiler.options.output.library.type !== 'commonjs2') {
warn('webpack config `output.libraryTarget` should be "commonjs2".');
}
if (!compiler.options.externals) {
tip(
'It is recommended to externalize dependencies in the server build for ' +
'better build performance.'
);
}
}; Also, again, in my case, entry points are now objects with - var entryAssets = entryInfo.assets.filter(isJS);
+ var entryAssets = entryInfo.assets.filter(file => isJS(file.name));
if (entryAssets.length > 1) {
throw new Error(
"Server-side bundle should have one single entry file. " +
"Avoid using CommonsChunkPlugin in the server config."
)
}
var entry = entryAssets[0];
- if (!entry || typeof entry !== 'string') {
+ if (!entry || typeof entry.name !== 'string') {
throw new Error(
("Entry \"" + entryName + "\" not found. Did you specify the correct entry option?")
)
}
var bundle = {
+ entry: entry.name,
files: {},
maps: {}
}; After these changes my bundle compiled correctly. |
Also, I think it's worth mentioning that even after my build succeeded I couldn't launch my bundle due to this error:
The problem was in function that starts on line TemplateRenderer.prototype.renderScripts = function renderScripts (context) {
var this$1 = this;
if (this.clientManifest) {
var initial = this.preloadFiles.filter(function (ref) {
var file = ref.file;
return isJS(file);
});
var async = (this.getUsedAsyncFiles(context) || []).filter(function (ref) {
var file = ref.file;
return isJS(file);
});
- var needed = [initial[0]].concat(async, initial.slice(1));
+ var needed = (initial.length ? [initial[0]] : []).concat(async, initial.slice(1));
return needed.map(function (ref) {
var file = ref.file;
return ("<script src=\"" + (this$1.publicPath) + file + "\" defer></script>")
}).join('')
} else {
return ''
}
}; It failed 'cause for some reason |
How to solve this problem? |
thanks |
Hi guys, facing the same issue. Is an update coming soon? |
Danail-Irinkov, this fix work fine. node_modules/vue-server-renderer/ search in files. BUT work only on build mode, my dev mode die. New version webpack-dev-middleware, i don't know how fix. |
Sure I applied the changes in local, but will have to fork for the main server if thats the solution. I am prerendering just my login and signup pages..., I tried excluding some imported elements, but still cant prerender the login page... It used to work fine before I updated to webpack5
|
@yyx990803 will you accept Pull Request if we fix it? |
I am also running into this issue with the following dependencies
My webpack server config contains
I am getting 2 errors (1) My libraryTarget does have commonjs2. (2)
I do have the main.js file at src/server/main.js as what is specified in the webpack config |
@se22as checkout this comment.
This problem is resolved by this code adjustment: - if (compiler.options.output && compiler.options.output.libraryTarget !== 'commonjs2') {
+ if (compiler.options.output && compiler.options.output.library.type !== 'commonjs2') {
This problem is resolved by this code adjustment: - if (!entry || typeof entry !== 'string') {
+ if (!entry || typeof entry.name !== 'string') { P.S. You should probably check the comment I linked above to resolve all issues related to this package. |
@efremenkovan thank you for your reply. Isn't the code change mentioned above involving changing code in node-modules. If that is the case, then as soon as i reinstall (or a colleague installs the deps) this code change has to be done again. If I have understood that correctly then this is not practical for an app i am about to release |
@se22as yeah, you are right about it being impractical, but there is no other workaround for now. The best thing you can do in case you really want to use webpack 5 in your project - create your own git repo with fixes and use it as plugin placeholder 'till it's updated. But I am not sure if it's worth it. I guess for prod. it's still better to use webpack v4 'cause it's wide support. |
@se22as @efremenkovan https://www.npmjs.com/package/patch-package is very good for this use case |
Instead of fixing var initialFiles = uniq(Object.keys(stats.entrypoints)
- .map(function (name) { return stats.entrypoints[name].assets })
+ .map(function (name) { return stats.entrypoints[name].assets.map(asset => asset.name) })
.reduce(function (assets, all) { return all.concat(assets); }, [])
.filter(function (file) { return isJS(file) || isCSS(file); })); Also one other fix I needed to make in client-plugin for production SSR was: stats.modules.forEach(function (m) {
// ignore modules duplicated in multiple chunks
if (m.chunks.length === 1) {
var cid = m.chunks[0];
var chunk = stats.chunks.find(function (c) { return c.id === cid; });
if (!chunk || !chunk.files) {
return
}
- var id = m.identifier.replace(/\s\w+$/, ''); // remove appended hash
+ var id = m.identifier.replace(/\|\w+$/, ''); // remove appended hash
var files = manifest.modules[hash(id)] = chunk.files.map(fileToIndex);
// find all asset modules associated with the same chunk
assetModules.forEach(function (m) {
if (m.chunks.some(function (id) { return id === cid; })) {
files.push.apply(files, m.assets.map(fileToIndex));
}
});
}
}); It looks like in webpack 5 the hash to a module identifier is appended with a | instead of a space. |
Error: Cannot find module '../js/290.26881f3c.js' Has anyone encountered this problem |
VERY IMPORTANT NOTE: at this commit date, in order to work properly with VueSSRServerPlugin on webpack.ssr.config.js must use WEBPACK VERSION 4, version 5 has an issue on fetching app entry file and output.libraryTarget, more details check vuejs/vue#11718
Are either #11863 or #11814 going to be merged or are none of them the ideal solution? Just curious because the changes in #11814 do seem to solve the problem (as @jreyesco16 suggested), yet the PR has been approved and not merged since Dec 10th. |
I'm running into the same problems. Are there plans to fix this so that Vue 2 SRR + Webpack 5 is possible? |
Half a year has passed |
This is preventing us from upgrading to webpack v5 because we are getting the output library issue. We need It because of a SSR memory leak issue that is caused by webpack v4 minimize. Will this be fixed soon? As that would possibly be quicker for us than upgrading to Vue v3. |
While it isn’t the most ideal solution, Using patch package and all of the fixes here in this issue thread, you can get things to work. I did it and am running webpack 5 with Vue ssr in prod with a big application. |
Thanks for the tip! I had no idea such a thing existed, I've been living under a rock |
The full set of changes I needed to make everything work. diff --git a/node_modules/vue-server-renderer/build.dev.js b/node_modules/vue-server-renderer/build.dev.js
index fb4caf5..541941d 100644
--- a/node_modules/vue-server-renderer/build.dev.js
+++ b/node_modules/vue-server-renderer/build.dev.js
@@ -9060,12 +9060,12 @@ TemplateRenderer.prototype.renderScripts = function renderScripts (context) {
var initial = this.preloadFiles.filter(function (ref) {
var file = ref.file;
- return isJS(file);
+ return isJS(file) && !file.endsWith('hot-update.js');
});
var async = (this.getUsedAsyncFiles(context) || []).filter(function (ref) {
var file = ref.file;
-
- return isJS(file);
+ // changed line
+ return isJS(file) && !file.endsWith('hot-update.js');
});
var needed = [initial[0]].concat(async, initial.slice(1));
return needed.map(function (ref) {
diff --git a/node_modules/vue-server-renderer/client-plugin.js b/node_modules/vue-server-renderer/client-plugin.js
index 15cdcbd..7b091cc 100644
--- a/node_modules/vue-server-renderer/client-plugin.js
+++ b/node_modules/vue-server-renderer/client-plugin.js
@@ -45,9 +45,12 @@ VueSSRClientPlugin.prototype.apply = function apply (compiler) {
.map(function (a) { return a.name; }));
var initialFiles = uniq(Object.keys(stats.entrypoints)
- .map(function (name) { return stats.entrypoints[name].assets; })
+ // changed line
+ .map(function (name) { return stats.entrypoints[name].assets.map(file => file.name); })
.reduce(function (assets, all) { return all.concat(assets); }, [])
- .filter(function (file) { return isJS(file) || isCSS(file); }));
+ .filter(function (file) {
+ return isJS(file) || isCSS(file);
+ }));
var asyncFiles = allFiles
.filter(function (file) { return isJS(file) || isCSS(file); })
@@ -71,7 +74,9 @@ VueSSRClientPlugin.prototype.apply = function apply (compiler) {
if (!chunk || !chunk.files) {
return
}
- var id = m.identifier.replace(/\s\w+$/, ''); // remove appended hash
+
+ // changed line
+ var id = m.identifier.replace(/\|\w+$/, ''); // remove appended hash
var files = manifest.modules[hash(id)] = chunk.files.map(fileToIndex);
// find all asset modules associated with the same chunk
assetModules.forEach(function (m) {
diff --git a/node_modules/vue-server-renderer/server-plugin.js b/node_modules/vue-server-renderer/server-plugin.js
index 54ba2b3..121bdc4 100644
--- a/node_modules/vue-server-renderer/server-plugin.js
+++ b/node_modules/vue-server-renderer/server-plugin.js
@@ -17,7 +17,8 @@ var validate = function (compiler) {
warn('webpack config `target` should be "node".');
}
- if (compiler.options.output && compiler.options.output.libraryTarget !== 'commonjs2') {
+ // changed line
+ if (compiler.options.output && compiler.options.output.library.type !== 'commonjs2') {
warn('webpack config `output.libraryTarget` should be "commonjs2".');
}
@@ -62,7 +63,8 @@ VueSSRServerPlugin.prototype.apply = function apply (compiler) {
return cb()
}
- var entryAssets = entryInfo.assets.filter(isJS);
+ // changed line
+ var entryAssets = entryInfo.assets.filter(file => isJS(file.name));
if (entryAssets.length > 1) {
throw new Error(
@@ -72,14 +74,16 @@ VueSSRServerPlugin.prototype.apply = function apply (compiler) {
}
var entry = entryAssets[0];
- if (!entry || typeof entry !== 'string') {
+ // changed line
+ if (!entry || typeof entry.name !== 'string') {
throw new Error(
("Entry \"" + entryName + "\" not found. Did you specify the correct entry option?")
)
}
var bundle = {
- entry: entry,
+ // changed line
+ entry: entry.name,
files: {},
maps: {}
};
donezo |
@trainiac I can confirm, this works 👍 Thanks for sharing. One oddity, I'd like to add is, that webpack throws a deprecation warning. Luckily it does currently not cause any issues :)
|
@trainiac: When I try to run server, I get Error: Invalid server-rendering bundle format. Should be a string or a bundle Object of type:
{
entry: string;
files: { [filename: string]: string; };
maps: { [filename: string]: string; };
} whereas my generated file has {
entry: {name: string};
files: { [filename: string]: string; };
maps: { [filename: string]: string; };
} |
Looks like you need the last change I’ve suggested. |
@trainiac : Yes. That was case. I was trusting message from PhpStorm, when it said patch successfully applied. Ended up using patch-package. |
Thank you brother |
cat fix-vue-ssr.patch | git apply - |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I encountered the same problem as you, have you solved it |
If you give me a reproduction repository, I can try to fix it |
Same issue UPDATED: it is fixed with @ndunks very helpful trick |
Why is it closed? Guess the solution is to upgrade to Vue 3 when upgrading to Webpack 5 |
@cartok because it was fixed in another PR (you can see the reference in this thread) |
@cjblomqvist thanks, but I still got the issue. Will maybe recheck if I did not mess it up elsewhere. |
It works fine for me |
all work fine
|
What problem does this feature solve?
github missing repository vuejs/vue-ssr-webpack-plugin, i update webpack to version 5 and have error
[vue-server-renderer-webpack-plugin] webpack config
output.libraryTarget
should be "commonjs2".What does the proposed API look like?
in my output.libraryTarget is libraryTarget: 'commonjs2'
The text was updated successfully, but these errors were encountered: