我把我的项目从CRA迁移到Vite。
当我运行npm run dev
时,我得到这个错误:
The following dependencies are imported but could not be resolved:
@mui/icons-material/Article (imported by /Blog/Admin/Exports.jsx)
@mui/icons-material/Comment (imported by /Social/Admin/Comment/View.jsx)
@mui/icons-material/TextSnippet (imported by /Contents/Admin/Page/List.jsx)
@mui/icons-material/FindInPage (imported by /Contents/Admin/Page/List.jsx)
@mui/icons-material/AccountTree (imported by /Taxonomy/Admin/Hierarchy/Manage.jsx)
@mui/icons-material/LocalOffer (imported by /Taxonomy/Admin/Tag/Manage.jsx)
@mui/icons-material/NoteAlt (imported by /Forms/Admin/Form/List.jsx)
@mui/icons-material/EventNote (imported by /Logs/Admin/Exports.jsx)
@mui/icons-material/Navigation (imported by /Navigation/Admin/Exports.jsx)
@mui/icons-material/Abc (imported by /Contents/Admin/Exports.jsx)
@mui/icons-material/Fingerprint (imported by /Entities/Admin/Exports.jsx)
@mui/icons-material/Support (imported by /Ticketing/Admin/Exports.jsx)
@mui/icons-material/Shuffle (imported by /Entities/Admin/EntityType/List.jsx)
@mui/icons-material/Delete (imported by /Logs/Admin/List.jsx)
@mui/icons-material/Search (imported by /Contents/Admin/Image/List.jsx)
@mui/icons-material/Done (imported by /Ticketing/Admin/Ticket/List.jsx)
@mui/icons-material/SyncAlt (imported by /Accounts/Admin/User/List.jsx)
@mui/icons-material/Error (imported by /Logs/Admin/List.jsx)
@mui/icons-material/ListAlt (imported by /Contents/Admin/Section/List.jsx)
@mui/icons-material/Message (imported by /Ticketing/Admin/Ticket/List.jsx)
@mui/icons-material/Link (imported by /Navigation/Admin/LinkGroup/List.jsx)
@mui/icons-material/Bolt (imported by /Contents/Admin/Section/List.jsx)
Are they installed?
即使我运行npm install
,然后运行npm run dev
,我看到这个消息。
我手动进入node_modules/@mui/icons-material
和cat Article.js
:
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _createSvgIcon = _interopRequireDefault(require("./utils/createSvgIcon"));
var _jsxRuntime = require("react/jsx-runtime");
var _default = (0, _createSvgIcon.default)( /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
d: "M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-5 14H7v-2h7v2zm3-4H7v-2h10v2zm0-4H7V7h10v2z"
}), 'Article');
exports.default = _default;
所以它在那里。我不明白为什么这件事不能解决。什么好主意吗?
mui图标文件具有.js
扩展名。在我们的vite配置中,我们只解析.ts
和.tsx
文件。添加.js
扩展名修复了这个错误。
我得到一个关于本地文件的错误。同样的信息:
下列依赖项已导入,但无法解析。
我的解决办法是添加"/"在我的文件名之前。所以"index.js"成为"。/index.js" .
这对我有用:
从package.json中删除插入符号(^)。
例如:
Before - "@mui/base": "^5.0.0-alpha.60"
After - "@mui/base": "5.0.0-alpha.60"