v-lazy-image icon indicating copy to clipboard operation
v-lazy-image copied to clipboard

Fix builds of VueJS 2 version in webpack@5

Open korya opened this issue 2 years ago • 5 comments

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 original package.json and fails
  • build-fixed that tries to build the project with the updated package.json and succeeds

This PR should solve https://github.com/alexjoverm/v-lazy-image/issues/106

korya avatar May 14 '22 20:05 korya

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 👍 .

Frantab avatar Sep 12 '22 10:09 Frantab

Hey! We also ran into the same issue. Would be great if you could merge this fix.

hliebe avatar Sep 12 '22 11:09 hliebe

Same issue in our project, a merge would be great, having to use v1.4.0 for now!

XPAULUSX avatar Apr 03 '23 09:04 XPAULUSX

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

korya avatar Apr 03 '23 16:04 korya

@alexjoverm is it possible for you to merge this PR please? It would help us solving our problems without any forks or workarounds. thx

hliebe avatar Sep 28 '23 12:09 hliebe