You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

jscodeshift始终跳过JS文件,Material-UI迁移脚本求助

Troubleshooting jscodeshift Skipping Files During Material-UI Migration

I’ve run into this exact frustration before when migrating Material-UI versions—let’s break down the most likely fixes for your issue:

1. Verify the Codemod Script Path

First, double-check that you’re pointing to the correct import-path.js script from the Material-UI codemod package. If you installed the package locally, your command should reference the script’s path within node_modules instead of just the filename. For example:

jscodeshift -t ./node_modules/@mui/material-codemod/v5.0.0/import-path.js Foo.js -v 2

(Adjust the path to match where your codemod package is installed—older versions might use material-ui-codemod instead of @mui/material-codemod.)

2. Add JSX Extension Support

Your Foo.js contains JSX, but jscodeshift doesn’t automatically parse JSX in .js files by default. Add the --extensions flag to tell it to handle both .js and .jsx files:

jscodeshift -t import-path.js Foo.js -v 2 --extensions .js,.jsx

This ensures the parser recognizes the JSX syntax in your component, so the codemod doesn’t skip it for being "unparseable" or non-matching.

3. Confirm the Codemod Targets Your Import Syntax

Take a quick look at the import-path.js script’s logic (open it in a text editor). The codemod only runs on files that match specific import patterns from Material-UI. Your import import Button from 'material-ui/Button' should be a match for v4-to-v5 migration, but if you’re using a script for a different version jump (like v3 to v4), it might not trigger. Make sure you’re using the correct script for your migration path.

4. Test with a Fresh Install

Sometimes cached package files or incorrect installations can cause issues. Try reinstalling the codemod package cleanly:

npm uninstall @mui/material-codemod
npm install @mui/material-codemod --save-dev

Then re-run your jscodeshift command with the correct local path.

Your Test Command & Component for Reference

Command you ran:

jscodeshift -t import-path.js Foo.js -v 2
Processing 1 files...
Spawning 1 workers...
Sending 1 files to free worker...
SKIP Foo.js
All done.
Results: 0 errors 0 unmodified 1 skipped 0 ok
Time elapsed: 0.696seconds

Your minimal component:

import React from 'react';
import Button from 'material-ui/Button'

const Foo = (props) => <Button>Hello</Button>;

export default Foo;

内容的提问来源于stack exchange,提问作者Gerb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:01:52