v-lazy-image
v-lazy-image copied to clipboard
Fix builds of VueJS 2 version in webpack@5
I cannot use this library in our app running on Vue2 and built with webpack v5. The error that I get is:
Module not found: Error: Package path ./v2 is not exported from package /Users/korya/dev/issue-webpack5-lazy-image/node_modules/v-lazy-image (see exports field in /Users/korya/dev/issue-webpack5-lazy-image/node_modules/v-lazy-image/package.json)
The proposed change fixes the problem.
I've created a minimal repo that demonstrates the problem https://github.com/korya/issue-webpack5-lazy-image/ and has some more details.
Also, this repo has 2 CI jobs defined (https://github.com/korya/issue-webpack5-lazy-image/actions/runs/2324999565):
-
build-as-is
that tries to build the project with the originalpackage.json
and fails -
build-fixed
that tries to build the project with the updatedpackage.json
and succeeds
This PR should solve https://github.com/alexjoverm/v-lazy-image/issues/106
hey 🙂 , would you mind merging this change? We need to use v2 and we have this issue too. I tried to apply your commit in node_modules and it works perfectly 👍 .
Hey! We also ran into the same issue. Would be great if you could merge this fix.
Same issue in our project, a merge would be great, having to use v1.4.0 for now!
We've added a post-install script to patch the package in node_modules/
. I will share the script here in a hope that this will be useful to someone.
Updates to package.json
:
{
...,
"scripts": {
...,
"postinstall": "./script/post-install.sh"
},
...
}
The contents of ./script/post-install.sh
:
#!/bin/bash
set -e
# XXX: Manually patch package.json of `v-lazy-image` to let webpack@5 build it
# successfully.
# For more details, refer to https://github.com/alexjoverm/v-lazy-image/pull/108
if [[ ! -f node_modules/v-lazy-image/package.json.original ]]; then
echo -e "\n\nPatching 'node_modules/v-lazy-image/package.json'..."
cp node_modules/v-lazy-image/package.json{,.original}
patch -p1 <<EOF
--- old/node_modules/v-lazy-image/package.json 2022-05-14 15:29:41.853865169 -0400
--- new/node_modules/v-lazy-image/package.json 2022-05-14 15:29:41.853865169 -0400
@@ -34,6 +34,10 @@
".": {
"import": "./dist/v-lazy-image.mjs",
"require": "./dist/v-lazy-image.js"
+ },
+ "./v2": {
+ "import": "./v2/v-lazy-image.mjs",
+ "require": "./v2/v-lazy-image.js"
}
},
"jest": {
EOF
echo -e "OK. Patched 'node_modules/v-lazy-image/package.json' successfully.\n\n"
else
echo -e "\n\nSkipped patching 'node_modules/v-lazy-image/package.json'.\n\n"
fi
@alexjoverm is it possible for you to merge this PR please? It would help us solving our problems without any forks or workarounds. thx