构建时可能会遇到这条报错
Module not found: Error: Can't resolve './xxx' in '/yourprojectdirectory/src' Did you mean 'xxx.js'? BREAKING CHANGE: The request './xxx' failed to resolve only because it was resolved as fully specified
一种解决办法:修改模块解析规则
{
test: /\.m?js/,
resolve: {
fullySpecified: false,
},
}
也可以给缺少扩展名的导入路径加上 .js
import xxx from './yourprojectdirectory/src/xxx';
// 改成:
import xxx from './yourprojectdirectory/src/xxx.js';
-
JahnoelRondon(2022 年 1 月 1 日),“type”: “module” with React,GitHub issue #11865。涉及 JavaScript MIME 类型、
.mjs,以及package.json声明"type": "module"的.js文件。https://github.com/facebook/create-react-app/issues/11865 -
user3130985(2022 年 2 月 3 日),关于 Create React App 中 Webpack 5 无法解析非完整路径的提问,Stack Overflow。https://stackoverflow.com/questions/70964723/webpack-5-in-ceate-react-app-cant-resolve-not-fully-specified-routes
-
puppe82(2022 年 12 月 28 日),Webpack 5: Import fails to resolve with Module not found error,GitHub issue #7114。https://github.com/fullcalendar/fullcalendar/issues/7114