代码之家  ›  专栏  ›  技术社区  ›  theJuls

MUI的codemod用于将jss组件转换为样式不起作用

  •  1
  • theJuls  · 技术社区  · 4 年前

    我正在从MUI v4迁移到v5。

    因此,我有无数的组件需要从 makeStyles API到样式或sx。

    根据他们的迁移 docs ,MUI有一个 codemod 脚本,它可能会使许多工作自动化。

    为了运行这个脚本,我作为开发依赖项安装了:

    npm安装-D@mui/codemod

    并按照医生的要求运行脚本:

    npx@mui/codemod v5.00/jss-to-styled/path/to/my/file/test.tsx

    不幸的是,这不起作用,我总是收到以下错误:

    TypeError: $ is not a function
        at Object.<anonymous> (/mypath/node_modules/core-js/modules/es.regexp.exec.js:7:1)
        at Module._compile (internal/modules/cjs/loader.js:1085:14)
        at Module._compile (/mypath/node_modules/pirates/lib/index.js:136:24)
        at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
        at Object.newLoader [as .js] (/mypath/node_modules/pirates/lib/index.js:141:7)
        at Module.load (internal/modules/cjs/loader.js:950:32)
        at Function.Module._load (internal/modules/cjs/loader.js:790:12)
        at Module.require (internal/modules/cjs/loader.js:974:19)
        at require (internal/modules/cjs/helpers.js:93:18)
        at Object.<anonymous> (/mypath/node_modules/core-js/internals/fix-regexp-well-known-symbol-logic.js
    

    我甚至用JS做了一个测试文件,看看它是否可行,但仍然一无所获。

    以下是我的测试文件的示例:

    import React from 'react'
    import Typography from '@mui/material/Typography'
    import makeStyles from '@mui/styles/makeStyles'
    
    const useStyles = makeStyles(() => ({
      typographyRoot: {
        color: 'red',
        backgroundColor: 'blue',
      },
    }))
    
    const Test = () => {
      const classes = useStyles()
      return (
        <Typography classes={{ root: classes.typographyRoot }}>
          Bla bla bla
        </Typography>
      )
    }
    
    export default Test
    

    有人知道我是否做错了什么,以及如何让它发挥作用吗?

    谢谢

    0 回复  |  直到 4 年前