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

[Bug]: Import error when trying to use cjs #9

Closed
codefln opened this issue Dec 14, 2023 · 2 comments · Fixed by #10
Closed

[Bug]: Import error when trying to use cjs #9

codefln opened this issue Dec 14, 2023 · 2 comments · Fixed by #10
Assignees
Labels
bug Something isn't working

Comments

@codefln
Copy link

codefln commented Dec 14, 2023

Provide environment information

@serwist/next@8.0.3

Which project is this issue for?

@serwist/next

Link to reproduction - Issues with a link to complete (but minimal) reproduction code help us address them faster

https://codesandbox.io/p/devbox/eloquent-kate-26hzzz?layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522clq5cq35i00093b6r2phk3uh3%2522%252C%2522sizes%2522%253A%255B70%252C30%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522clq5cq35h00023b6rt4lzp68k%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522clq5cq35h00063b6rwfki12rr%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522clq5cq35h00083b6ryjyal06n%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B50%252C50%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clq5cq35h00023b6rt4lzp68k%2522%253A%257B%2522id%2522%253A%2522clq5cq35h00023b6rt4lzp68k%2522%252C%2522tabs%2522%253A%255B%255D%257D%252C%2522clq5cq35h00083b6ryjyal06n%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clq5cq35h00073b6rdm9bxsyu%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_PORT%2522%252C%2522taskId%2522%253A%2522dev%2522%252C%2522port%2522%253A3000%252C%2522path%2522%253A%2522%252F%2522%257D%255D%252C%2522id%2522%253A%2522clq5cq35h00083b6ryjyal06n%2522%252C%2522activeTabId%2522%253A%2522clq5cq35h00073b6rdm9bxsyu%2522%257D%252C%2522clq5cq35h00063b6rwfki12rr%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clq5cq35h00033b6rmkg06pgy%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522dev%2522%257D%252C%257B%2522id%2522%253A%2522clq5cq35h00043b6rv4z80cli%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522start%2522%257D%252C%257B%2522id%2522%253A%2522clq5cq35h00053b6rc94ys9ea%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522install%2522%257D%255D%252C%2522id%2522%253A%2522clq5cq35h00063b6rwfki12rr%2522%252C%2522activeTabId%2522%253A%2522clq5cq35h00033b6rmkg06pgy%2522%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Atrue%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D

To reproduce

in next.config.js

const withSerwistInit = require("@serwist/next");

const withSerwist = withSerwistInit({
cacheOnFrontEndNav: true,
swSrc: "app/sw.ts",
swDest: "public/sw.js",
});

/** @type {import("next").NextConfig} */
const nextConfig = {
reactStrictMode: true,
};

module.exports = withSerwist(nextConfig);

num run build

Describe the bug

When I am try import cjs like
const withSerwistInit = require("@serwist/next");

I got a error

Error [ERR_REQUIRE_ESM]: require() of ES Module /workspaces/sandbox/node_modules/pretty-bytes/index.js from /workspaces/sandbox/node_modules/@serwist/build/dist/index.old.cjs not supported.
Instead change the require of index.js in /workspaces/sandbox/node_modules/@serwist/build/dist/index.old.cjs to a dynamic import() which is available in all CommonJS modules.

Expected behavior

Regular build

Screenshots (if relevant)

No response

Additional information (if relevant)

No response

@codefln codefln added bug Something isn't working triage New issues get this label, remove it after triage labels Dec 14, 2023
@DuCanhGH
Copy link
Member

DuCanhGH commented Dec 14, 2023

Oops, seems that pretty-bytes is now an ESM package. Fixing this soon!

@DuCanhGH
Copy link
Member

Fixed in 8.0.4 :) Give it a try.

@DuCanhGH DuCanhGH removed the triage New issues get this label, remove it after triage label Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants