Skip to content
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

Fix builds of VueJS 2 version in webpack@5 #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

korya
Copy link

@korya korya commented May 14, 2022

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 #106

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
@Frantab
Copy link

Frantab commented Sep 12, 2022

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

@hliebe
Copy link

hliebe commented Sep 12, 2022

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

Copy link

@hliebe hliebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

Copy link

@mr-mahawar mr-mahawar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We too are facing this issue in our project, please merge it team!

@XPAULUSX
Copy link

XPAULUSX commented Apr 3, 2023

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

@korya
Copy link
Author

korya commented Apr 3, 2023

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

@hliebe
Copy link

hliebe commented Sep 28, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants