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

Importing next/link in async component produces error #204

Closed
gaetansnl opened this issue Aug 13, 2024 · 9 comments · Fixed by #228
Closed

Importing next/link in async component produces error #204

gaetansnl opened this issue Aug 13, 2024 · 9 comments · Fixed by #228
Assignees
Labels
bug 🐛 Something doesn't work nextjs v6.x

Comments

@gaetansnl
Copy link

gaetansnl commented Aug 13, 2024

Steps to reproduce

Link to live example: (required)

Steps:

  1. Do PigmentCSS migration on new nextjs project with MUI V6

  2. Use next/link in async component

     import { List, ListItemButton, ListItemText } from "@mui/material";
     import NextLink from "next/link";
     
     export default async function Home() {
       return (
         <List sx={{ width: "100%", height: "100%", overflowY: "scroll" }}>
           <ListItemButton href={{ pathname: `/documents` }} component={NextLink}>
             <ListItemText primary={"gg"} />
           </ListItemButton>
         </List>
       );
     }

Current behavior

EvalError: Cannot assign to read only property '__esModule' of object '[object Object]' in/app/node_modules/next/dist/client/link.js
| /app/node_modules/next/link.js
| /app/app/page.tsx

    at Module.evaluate (/app/node_modules/@wyw-in-js/transform/lib/module.js:224:13)
    at require.Object.assign.ensure (/app/node_modules/@wyw-in-js/transform/lib/module.js:118:7)
    at newRequire (/app/node_modules/@pigment-css/unplugin/build/index.js:110:12)
    at /app/node_modules/next/link.js:1:40
    at /app/node_modules/next/link.js:3:3
    at Script.runInContext (node:vm:148:12)
    at Module.evaluate (/app/node_modules/@wyw-in-js/transform/lib/module.js:209:14)
    at require.Object.assign.ensure (/app/node_modules/@wyw-in-js/transform/lib/module.js:118:7)
    at newRequire (/app/node_modules/@pigment-css/unplugin/build/index.js:110:12)
    at /app/app/page.tsx:14:36
    at /app/app/page.tsx:166:3
    at Script.runInContext (node:vm:148:12)
    at Module.evaluate (/app/node_modules/@wyw-in-js/transform/lib/module.js:209:14)
    at evaluate (/app/node_modules/@wyw-in-js/transform/lib/evaluators/index.js:14:5)
    at BaseAction.evalFile (/app/node_modules/@wyw-in-js/transform/lib/transform/generators/evalFile.js:35:43)
    at evalFile.next (<anonymous>)
    at /app/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:66:78
    at EventEmitter.action (/app/node_modules/@wyw-in-js/transform/lib/utils/EventEmitter.js:25:22)
    at BaseAction.emitAction (/app/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:131:39)
    at nextFn (/app/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:66:32)
    at processNext (/app/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:111:28)
    at Object.next (/app/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:120:9)
    at asyncActionRunner (/app/node_modules/@wyw-in-js/transform/lib/transform/actions/actionRunner.js:39:102)
    at async asyncActionRunner (/app/node_modules/@wyw-in-js/transform/lib/transform/actions/actionRunner.js:46:22)
    at async Object.transform (/app/node_modules/@wyw-in-js/transform/lib/transform.js:107:20)
    at async Object.transform (/app/node_modules/@pigment-css/unplugin/build/index.js:273:24)
    at async Object.transform (/app/node_modules/unplugin/dist/webpack/loaders/transform.js:108:15)
 ⨯ unhandledRejection: /app/node_modules/@wyw-in-js/transform/lib/module.js:224
      throw new EvalError(`${e.message} in${this.callstack.join('\n| ')}\n`);

Expected behavior

No error

Context

No response

Your environment

npx @mui/envinfo
 
  System:
    OS: macOS 14.3.1
  Binaries:
    Node: 22.5.1 - /opt/homebrew/bin/node
    npm: 10.8.2 - /opt/homebrew/bin/npm
    pnpm: 9.6.0 - /opt/homebrew/bin/pnpm
  Browsers:
    Chrome: 127.0.6533.100
    Edge: Not Found
    Safari: 17.3.1
  npmPackages:
    @emotion/react:  11.13.0 
    @emotion/styled:  11.13.0 
    @mui/core-downloads-tracker:  6.0.0-dev.240424162023-9968b4889d 
    @mui/icons-material: next => 6.0.0-beta.5 
    @mui/material: next => 6.0.0-beta.5 
    @mui/material-pigment-css: next => 6.0.0-beta.5-dev.20240809-114550-93cb3d65e7 
    @mui/private-theming:  6.0.0-beta.5-dev.20240809-114550-93cb3d65e7 
    @mui/styled-engine:  6.0.0-beta.5 
    @mui/system:  6.0.0-beta.5-dev.20240809-114550-93cb3d65e7 
    @mui/types:  7.2.15 
    @mui/utils:  6.0.0-beta.5-dev.20240809-114550-93cb3d65e7 
    @types/react: ^18 => 18.3.3 
    react: ^18 => 18.3.1 
    react-dom: ^18 => 18.3.1 
    typescript: ^5 => 5.5.4 

Search keywords: next/link pigmentcss

Search keywords:

@gaetansnl gaetansnl added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Aug 13, 2024
@zannager zannager added package: system Specific to @mui/system v6.x labels Aug 13, 2024
@aarongarciah
Copy link
Member

@gaetansnl can you provide a sandbox or repository so we can properly check?

@aarongarciah aarongarciah added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Aug 14, 2024
@gaetansnl
Copy link
Author

@aarongarciah here is a minimal reproduction https://codesandbox.io/p/devbox/peaceful-estrela-5qtqsj

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Aug 15, 2024
@aarongarciah
Copy link
Member

Just tested your sandbox locally and I reproduced the issue. Here's the full error output:

Error
/sandbox/node_modules/@wyw-in-js/transform/lib/module.js:224
      throw new EvalError(`${e.message} in${this.callstack.join('\n| ')}\n`);
      ^

EvalError: Cannot assign to read only property '__esModule' of object '[object Object]' in/sandbox/node_modules/next/dist/client/link.js
| /sandbox/node_modules/next/link.js
| /sandbox/app/page.tsx

    at Module.evaluate (/sandbox/node_modules/@wyw-in-js/transform/lib/module.js:224:13)
    at require.Object.assign.ensure (/sandbox/node_modules/@wyw-in-js/transform/lib/module.js:118:7)
    at newRequire (/sandbox/node_modules/@pigment-css/unplugin/build/index.js:110:12)
    at /sandbox/node_modules/next/link.js:1:40
    at /sandbox/node_modules/next/link.js:3:3
    at Script.runInContext (node:vm:133:12)
    at Module.evaluate (/sandbox/node_modules/@wyw-in-js/transform/lib/module.js:209:14)
    at require.Object.assign.ensure (/sandbox/node_modules/@wyw-in-js/transform/lib/module.js:118:7)
    at newRequire (/sandbox/node_modules/@pigment-css/unplugin/build/index.js:110:12)
    at /sandbox/app/page.tsx:12:36
    at /sandbox/app/page.tsx:67:3
    at Script.runInContext (node:vm:133:12)
    at Module.evaluate (/sandbox/node_modules/@wyw-in-js/transform/lib/module.js:209:14)
    at evaluate (/sandbox/node_modules/@wyw-in-js/transform/lib/evaluators/index.js:14:5)
    at BaseAction.evalFile (/sandbox/node_modules/@wyw-in-js/transform/lib/transform/generators/evalFile.js:35:43)
    at evalFile.next (<anonymous>)
    at /sandbox/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:66:78
    at EventEmitter.action (/sandbox/node_modules/@wyw-in-js/transform/lib/utils/EventEmitter.js:25:22)
    at BaseAction.emitAction (/sandbox/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:131:39)
    at nextFn (/sandbox/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:66:32)
    at processNext (/sandbox/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:111:28)
    at Object.next (/sandbox/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:120:9)
    at asyncActionRunner (/sandbox/node_modules/@wyw-in-js/transform/lib/transform/actions/actionRunner.js:39:102)
    at async asyncActionRunner (/sandbox/node_modules/@wyw-in-js/transform/lib/transform/actions/actionRunner.js:46:22)
    at async Object.transform (/sandbox/node_modules/@wyw-in-js/transform/lib/transform.js:107:20)
    at async Object.transform (/sandbox/node_modules/@pigment-css/unplugin/build/index.js:273:24)
    at async Object.transform (/sandbox/node_modules/unplugin/dist/webpack/loaders/transform.js:108:15)
 ⨯ unhandledRejection: /sandbox/node_modules/@wyw-in-js/transform/lib/module.js:224
      throw new EvalError(`${e.message} in${this.callstack.join('\n| ')}\n`);
      ^

EvalError: Cannot assign to read only property '__esModule' of object '[object Object]' in/sandbox/node_modules/next/dist/client/link.js
| /sandbox/node_modules/next/link.js
| /sandbox/app/page.tsx

    at Module.evaluate (/sandbox/node_modules/@wyw-in-js/transform/lib/module.js:224:13)
    at require.Object.assign.ensure (/sandbox/node_modules/@wyw-in-js/transform/lib/module.js:118:7)
    at newRequire (/sandbox/node_modules/@pigment-css/unplugin/build/index.js:110:12)
    at /sandbox/node_modules/next/link.js:1:40
    at /sandbox/node_modules/next/link.js:3:3
    at Script.runInContext (node:vm:133:12)
    at Module.evaluate (/sandbox/node_modules/@wyw-in-js/transform/lib/module.js:209:14)
    at require.Object.assign.ensure (/sandbox/node_modules/@wyw-in-js/transform/lib/module.js:118:7)
    at newRequire (/sandbox/node_modules/@pigment-css/unplugin/build/index.js:110:12)
    at /sandbox/app/page.tsx:12:36
    at /sandbox/app/page.tsx:67:3
    at Script.runInContext (node:vm:133:12)
    at Module.evaluate (/sandbox/node_modules/@wyw-in-js/transform/lib/module.js:209:14)
    at evaluate (/sandbox/node_modules/@wyw-in-js/transform/lib/evaluators/index.js:14:5)
    at BaseAction.evalFile (/sandbox/node_modules/@wyw-in-js/transform/lib/transform/generators/evalFile.js:35:43)
    at evalFile.next (<anonymous>)
    at /sandbox/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:66:78
    at EventEmitter.action (/sandbox/node_modules/@wyw-in-js/transform/lib/utils/EventEmitter.js:25:22)
    at BaseAction.emitAction (/sandbox/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:131:39)
    at nextFn (/sandbox/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:66:32)
    at processNext (/sandbox/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:111:28)
    at Object.next (/sandbox/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:120:9)
    at asyncActionRunner (/sandbox/node_modules/@wyw-in-js/transform/lib/transform/actions/actionRunner.js:39:102)
    at async asyncActionRunner (/sandbox/node_modules/@wyw-in-js/transform/lib/transform/actions/actionRunner.js:46:22)
    at async Object.transform (/sandbox/node_modules/@wyw-in-js/transform/lib/transform.js:107:20)
    at async Object.transform (/sandbox/node_modules/@pigment-css/unplugin/build/index.js:273:24)
    at async Object.transform (/sandbox/node_modules/unplugin/dist/webpack/loaders/transform.js:108:15)
 ⨯ unhandledRejection: /sandbox/node_modules/@wyw-in-js/transform/lib/module.js:224
      throw new EvalError(`${e.message} in${this.callstack.join('\n| ')}\n`);
      ^

EvalError: Cannot assign to read only property '__esModule' of object '[object Object]' in/sandbox/node_modules/next/dist/client/link.js
| /sandbox/node_modules/next/link.js
| /sandbox/app/page.tsx

    at Module.evaluate (/sandbox/node_modules/@wyw-in-js/transform/lib/module.js:224:13)
    at require.Object.assign.ensure (/sandbox/node_modules/@wyw-in-js/transform/lib/module.js:118:7)
    at newRequire (/sandbox/node_modules/@pigment-css/unplugin/build/index.js:110:12)
    at /sandbox/node_modules/next/link.js:1:40
    at /sandbox/node_modules/next/link.js:3:3
    at Script.runInContext (node:vm:133:12)
    at Module.evaluate (/sandbox/node_modules/@wyw-in-js/transform/lib/module.js:209:14)
    at require.Object.assign.ensure (/sandbox/node_modules/@wyw-in-js/transform/lib/module.js:118:7)
    at newRequire (/sandbox/node_modules/@pigment-css/unplugin/build/index.js:110:12)
    at /sandbox/app/page.tsx:12:36
    at /sandbox/app/page.tsx:67:3
    at Script.runInContext (node:vm:133:12)
    at Module.evaluate (/sandbox/node_modules/@wyw-in-js/transform/lib/module.js:209:14)
    at evaluate (/sandbox/node_modules/@wyw-in-js/transform/lib/evaluators/index.js:14:5)
    at BaseAction.evalFile (/sandbox/node_modules/@wyw-in-js/transform/lib/transform/generators/evalFile.js:35:43)
    at evalFile.next (<anonymous>)
    at /sandbox/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:66:78
    at EventEmitter.action (/sandbox/node_modules/@wyw-in-js/transform/lib/utils/EventEmitter.js:25:22)
    at BaseAction.emitAction (/sandbox/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:131:39)
    at nextFn (/sandbox/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:66:32)
    at processNext (/sandbox/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:111:28)
    at Object.next (/sandbox/node_modules/@wyw-in-js/transform/lib/transform/actions/BaseAction.js:120:9)
    at asyncActionRunner (/sandbox/node_modules/@wyw-in-js/transform/lib/transform/actions/actionRunner.js:39:102)
    at async asyncActionRunner (/sandbox/node_modules/@wyw-in-js/transform/lib/transform/actions/actionRunner.js:46:22)
    at async Object.transform (/sandbox/node_modules/@wyw-in-js/transform/lib/transform.js:107:20)
    at async Object.transform (/sandbox/node_modules/@pigment-css/unplugin/build/index.js:273:24)
    at async Object.transform (/sandbox/node_modules/unplugin/dist/webpack/loaders/transform.js:108:15)

cc @brijeshb42 @siriwatknp

@aarongarciah aarongarciah added bug 🐛 Something doesn't work nextjs and removed package: system Specific to @mui/system labels Aug 15, 2024
@aarongarciah aarongarciah changed the title V6 next/link import produces error with pigmentcss [pigment-css] next/link import produces error Aug 15, 2024
@aarongarciah aarongarciah transferred this issue from mui/material-ui Aug 15, 2024
@aarongarciah aarongarciah changed the title [pigment-css] next/link import produces error Importing next/link produces error Aug 15, 2024
@siriwatknp siriwatknp changed the title Importing next/link produces error Importing next/link in async component produces error Aug 15, 2024
@siriwatknp
Copy link
Member

siriwatknp commented Aug 15, 2024

Found that the error occur when the component is async.

This is the before transformation that wyw-in-js tries to evaluate:

"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.__wywPreval = void 0;
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/asyncToGenerator"));
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _jsxDevRuntime = require("react/jsx-dev-runtime");
var _material = require("__barrel_optimize__?names=List,ListItemButton,ListItemText!=!@mui/material");
var _link = _interopRequireDefault(require("next/link"));
var _exp = /*#__PURE__*/function _exp() {
  return {
    width: "100%",
    height: "100%",
    overflowY: "scroll"
  };
};
var _exp2 = /*#__PURE__*/function _exp2() {
  return _material.List;
};
function _Home() {
  _Home = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
    return _regenerator["default"].wrap(function _callee$(_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          return _context.abrupt("return", /*#__PURE__*/(0, _jsxDevRuntime.jsxDEV)(_material.List, {
            sx: "s1bdmy7h",
            children: /*#__PURE__*/(0, _jsxDevRuntime.jsxDEV)(_material.ListItemButton, {
              href: {
                pathname: "/documents"
              },
              component: _link["default"],
              children: /*#__PURE__*/(0, _jsxDevRuntime.jsxDEV)(_material.ListItemText, {
                primary: "gg"
              }, void 0, false, {
                fileName: "/Users/siriwatknp/practice-repos/material-ui-v6-nextjs-pigment/src/app/page.tsx",
                lineNumber: 8,
                columnNumber: 9
              }, this)
            }, void 0, false, {
              fileName: "/Users/siriwatknp/practice-repos/material-ui-v6-nextjs-pigment/src/app/page.tsx",
              lineNumber: 7,
              columnNumber: 7
            }, this)
          }, void 0, false, {
            fileName: "/Users/siriwatknp/practice-repos/material-ui-v6-nextjs-pigment/src/app/page.tsx",
            lineNumber: 6,
            columnNumber: 5
          }, this));
        case 1:
        case "end":
          return _context.stop();
      }
    }, _callee, this);
  }));
  return _Home.apply(this, arguments);
}
var __wywPreval = exports.__wywPreval = {
  _exp: _exp,
  _exp2: _exp2
};

A lot of modules are not necessary to be evaluated. I am not sure if Pigment CSS supports async component already.

@siriwatknp siriwatknp changed the title Importing next/link in async component produces error Importing next/link in async component produces error Aug 15, 2024
@siriwatknp siriwatknp removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Aug 15, 2024
@rkurbatov
Copy link

rkurbatov commented Aug 16, 2024

#206 - interesting, I just reported the very same error that happens on NextJS v12 when I use next-i18next useTranslate() hook.

@samuelgoldenbaum
Copy link

samuelgoldenbaum commented Sep 10, 2024

I am finding it challenging to stay positive and take this library seriously in its current state, with so many issues with elementary requirements like this, which was reported more than a month ago. Yet, docs are saying:

...it is recommended to fully migrate to Pigment CSS in the end.

I've been using mui for many years at the enterprise level, but this is just painful.

@brijeshb42
Copy link
Contributor

Apologies for the delay. This particular issue went completely out of my radar. I'll post an update when I have a fix.
Note that this is an alpha release right now and we are trying to fix as much issues as we can before a stable release.

@siriwatknp
Copy link
Member

I am finding it challenging to stay positive and take this library seriously in its current state, with so many issues with elementary requirements like this, which was reported more than a month ago

Sorry for the confusion, what the docs trying to say is to have one styling solution at the end (either Emotion or Pigment CSS).

If you don't have any problem using Emotion as a styling engine, I don't see any reason for you to migrate to Pigment CSS.

@aleksandrjet
Copy link

I saw that it has #228, but the problem still keeps. I got to reproduce this in curl https://codeload.github.com/mui/pigment-css/tar.gz/master | tar -xz --strip=2 pigment-css-master/examples/pigment-css-nextjs-ts by addingimport NextLink from 'next/link' and make the page is async

I used next@14.2.11 and @pigment-css/nextjs-plugin@0.0.22

Is there any understanding when it will fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work nextjs v6.x
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants