-
-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Error: Dynamic require of "workbox-build" is not supported #667
Comments
Hi guys, I have updates. I updated my github runner to macos-14 and isn't showing the error anymore. The bad part is that we can't use macos-14, we have a self hosted runner that works on ubuntu-latest, so we need to get this fix for ubuntu. GH Action on macos-14 that doesn't show the error:
|
I could fix this issue by adding |
I've got the same issue when trying to build inside a nuxt application on Vercel, even with |
I'm having this issue now, building both locally (OS X 14.4) and on a gitlab runner (with the vite-plugin-pwa/src/modules.ts Line 19 in f7f3147
(When this line fails, the try/catch block kicks over into a require statement that presumably is throwing the error.) Unfortunately this is preventing us from being able to upgrade nuxt/devtools to deal with a CVE, so it's an important problem that we will need to revisit shortly. The workbox-build fix did not work for us either. |
I had the same issue, deleting the |
Any body can fix this issue? |
I added two patches to make it build correctly on vercel. diff --git a/dist/index.js b/dist/index.js
index 147595f4a60b83ffa7316ed2c99be688e95f9fbd..74da4b11aba6a5b2d5e12bbfcf55da56015767ba 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -17,6 +17,10 @@ import {
import { readFileSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
+
+import { createRequire } from 'node:module';
+const require = createRequire(import.meta.url);
+
function createContext(userOptions) {
const _dirname2 = typeof __dirname !== "undefined" ? __dirname : dirname(fileURLToPath(import.meta.url));
const { version } = JSON.parse(
@@ -276,8 +280,8 @@ import.meta.hot.on('${DEV_PWA_ASSETS_NAME}', ({ themeColor, links }) => {
else link.removeAttribute('type');
if (!link.parentNode) document.head.appendChild(link);
});
- }
-});
+ }
+});
function registerDevSW() {
try {
import.meta.hot.send('${DEV_READY_NAME}');
@@ -303,7 +307,7 @@ async function loadWorkboxBuild() {
const workbox = await import("workbox-build");
return workbox.default ?? workbox;
} catch (_) {
- return __require("workbox-build");
+ return require("workbox-build");
}
}
async function generateRegisterSW2(options, mode, source = "register") { The first one is to solve that the output code of esbuild on vercel cannot require diff --git a/package.json b/package.json
index a832ba9fc48f08300d8e5e595409c0488217af86..23af6ad8e16a8add0580151e8124f71451ebfc94 100644
--- a/package.json
+++ b/package.json
@@ -23,8 +23,8 @@
"engines": {
"node": ">=0.10.0"
},
- "main": "./jsonpointer",
- "typings": "jsonpointer.d.ts",
+ "main": "./jsonpointer.js",
+ "typings": "./jsonpointer.d.ts",
"files": [
"jsonpointer.js",
"jsonpointer.d.ts" The second one is to require
|
@hyoban can you check with pkg-pr-new version from this PR #781 (comment) ? |
There is no problem with |
@BernardoSM @hyoban released |
My local computer config that doesn't show the error below: ✅
My gh actions config that shows the error below: 🚨
Linux
v20.9.0
3.10.2
3.10.1
2.8.1
yarn@1.22.21
-
-
-
-
The text was updated successfully, but these errors were encountered: