当前位置: 首页 > 面试题库 >

创建react app错误:找不到模块'./locale'

夹谷信鸿
2023-03-14
问题内容

我用 create-react-app 引导了我的应用 程序 ,当我运行我的应用程序时,它会编译并带有警告,并在浏览器中引发错误。

编译时出错

./node_modules/rc-picker/node_modules/moment/src/lib/locale/locales.js
Module not found: Can't resolve './locale' in '/Users/macbook/Desktop/projects/pizza/Yummi-fend/node_modules/rc-picker/node_modules/moment/src/lib/locale'

浏览器错误

Error: Cannot find module './locale'
▶ 2 stack frames were collapsed.
__webpack_require__
/Users/macbook/Desktop/projects/pizza/Yummi-fend/webpack/bootstrap:784
  781 | };
  782 | 
  783 | // Execute the module function
> 784 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
      | ^  785 | 
  786 | // Flag the module as loaded
  787 | module.l = true;
View compiled
fn
/Users/macbook/Desktop/projects/pizza/Yummi-fend/webpack/bootstrap:150
  147 |         );
  148 |         hotCurrentParents = [];
  149 |     }
> 150 |     return __webpack_require__(request);
      | ^  151 | };
  152 | var ObjectFactory = function ObjectFactory(name) {
  153 |     return {
View compiled
Module../node_modules/moment/src/lib/moment/moment.js
node_modules/moment/src/lib/moment/moment.js:1
__webpack_require__
/Users/macbook/Desktop/projects/pizza/Yummi-fend/webpack/bootstrap:784
  781 | };
  782 | 
  783 | // Execute the module function
> 784 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
      | ^  785 | 
  786 | // Flag the module as loaded
  787 | module.l = true;
View compiled
fn
/Users/macbook/Desktop/projects/pizza/Yummi-fend/webpack/bootstrap:150
  147 |         );
  148 |         hotCurrentParents = [];
  149 |     }
> 150 |     return __webpack_require__(request);
      | ^  151 | };
  152 | var ObjectFactory = function ObjectFactory(name) {
  153 |     return {
View compiled
Module../node_modules/moment/src/moment.js
node_modules/moment/src/moment.js:1
__webpack_require__
/Users/macbook/Desktop/projects/pizza/Yummi-fend/webpack/bootstrap:784
  781 | };
  782 | 
  783 | // Execute the module function
> 784 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
      | ^  785 | 
  786 | // Flag the module as loaded
  787 | module.l = true;
View compiled
fn
/Users/macbook/Desktop/projects/pizza/Yummi-fend/webpack/bootstrap:150
  147 |         );
  148 |         hotCurrentParents = [];
  149 |     }
> 150 |     return __webpack_require__(request);
      | ^  151 | };
  152 | var ObjectFactory = function ObjectFactory(name) {
  153 |     return {
View compiled
Module../node_modules/rc-picker/es/generate/moment.js
node_modules/rc-picker/es/generate/moment.js:1
__webpack_require__
/Users/macbook/Desktop/projects/pizza/Yummi-fend/webpack/bootstrap:784
  781 | };
  782 | 
  783 | // Execute the module function
> 784 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
      | ^  785 | 
  786 | // Flag the module as loaded
  787 | module.l = true;
View compiled
fn
/Users/macbook/Desktop/projects/pizza/Yummi-fend/webpack/bootstrap:150
  147 |         );
  148 |         hotCurrentParents = [];
  149 |     }
> 150 |     return __webpack_require__(request);
      | ^  151 | };
  152 | var ObjectFactory = function ObjectFactory(name) {
  153 |     return {
View compiled
Module../node_modules/antd/es/calendar/index.js
node_modules/antd/es/calendar/index.js:1
__webpack_require__
/Users/macbook/Desktop/projects/pizza/Yummi-fend/webpack/bootstrap:784
  781 | };
  782 | 
  783 | // Execute the module function
> 784 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
      | ^  785 | 
  786 | // Flag the module as loaded
  787 | module.l = true;
View compiled
fn
/Users/macbook/Desktop/projects/pizza/Yummi-fend/webpack/bootstrap:150
  147 |         );
  148 |         hotCurrentParents = [];
  149 |     }
> 150 |     return __webpack_require__(request);
      | ^  151 | };
  152 | var ObjectFactory = function ObjectFactory(name) {
  153 |     return {
View compiled
Module../node_modules/antd/es/index.js
node_modules/antd/es/index.js:3
__webpack_require__
/Users/macbook/Desktop/projects/pizza/Yummi-fend/webpack/bootstrap:784
  781 | };
  782 | 
  783 | // Execute the module function
> 784 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
      | ^  785 | 
  786 | // Flag the module as loaded
  787 | module.l = true;
View compiled
fn
/Users/macbook/Desktop/projects/pizza/Yummi-fend/webpack/bootstrap:150
  147 |         );
  148 |         hotCurrentParents = [];
  149 |     }
> 150 |     return __webpack_require__(request);
      | ^  151 | };
  152 | var ObjectFactory = function ObjectFactory(name) {
  153 |     return {
View compiled
Module../src/components/AuthPage/loginPage.js
http://localhost:3000/static/js/main.chunk.js:313:62
__webpack_require__
/Users/macbook/Desktop/projects/pizza/Yummi-fend/webpack/bootstrap:784
  781 | };
  782 | 
  783 | // Execute the module function
> 784 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
      | ^  785 | 
  786 | // Flag the module as loaded
  787 | module.l = true;
View compiled
fn
/Users/macbook/Desktop/projects/pizza/Yummi-fend/webpack/bootstrap:150
  147 |         );
  148 |         hotCurrentParents = [];
  149 |     }
> 150 |     return __webpack_require__(request);
      | ^  151 | };
  152 | var ObjectFactory = function ObjectFactory(name) {
  153 |     return {
View compiled
Module../src/App.js
http://localhost:3000/static/js/main.chunk.js:127:88
__webpack_require__
/Users/macbook/Desktop/projects/pizza/Yummi-fend/webpack/bootstrap:784
  781 | };
  782 | 
  783 | // Execute the module function
> 784 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
      | ^  785 | 
  786 | // Flag the module as loaded
  787 | module.l = true;
View compiled
fn
/Users/macbook/Desktop/projects/pizza/Yummi-fend/webpack/bootstrap:150
  147 |         );
  148 |         hotCurrentParents = [];
  149 |     }
> 150 |     return __webpack_require__(request);
      | ^  151 | };
  152 | var ObjectFactory = function ObjectFactory(name) {
  153 |     return {
View compiled
Module../src/index.js
http://localhost:3000/static/js/main.chunk.js:1595:62
__webpack_require__
/Users/macbook/Desktop/projects/pizza/Yummi-fend/webpack/bootstrap:784
  781 | };
  782 | 
  783 | // Execute the module function
> 784 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
      | ^  785 | 
  786 | // Flag the module as loaded
  787 | module.l = true;
View compiled
fn
/Users/macbook/Desktop/projects/pizza/Yummi-fend/webpack/bootstrap:150
  147 |         );
  148 |         hotCurrentParents = [];
  149 |     }
> 150 |     return __webpack_require__(request);
      | ^  151 | };
  152 | var ObjectFactory = function ObjectFactory(name) {
  153 |     return {
View compiled
1
http://localhost:3000/static/js/main.chunk.js:1737:18
__webpack_require__
/Users/macbook/Desktop/projects/pizza/Yummi-fend/webpack/bootstrap:784
  781 | };
  782 | 
  783 | // Execute the module function
> 784 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
      | ^  785 | 
  786 | // Flag the module as loaded
  787 | module.l = true;
View compiled
checkDeferredModules
/Users/macbook/Desktop/projects/pizza/Yummi-fend/webpack/bootstrap:45
  42 |  }
  43 |  if(fulfilled) {
  44 |      deferredModules.splice(i--, 1);
> 45 |      result = __webpack_require__(__webpack_require__.s = deferredModule[0]);
     | ^  46 |  }
  47 | }
  48 | 
View compiled
Array.webpackJsonpCallback [as push]
/Users/macbook/Desktop/projects/pizza/Yummi-fend/webpack/bootstrap:32
  29 |  deferredModules.push.apply(deferredModules, executeModules || []);
  30 | 
  31 |  // run deferred modules when all chunks ready
> 32 |  return checkDeferredModules();
     | ^  33 | };
  34 | function checkDeferredModules() {
  35 |  var result;
View compiled
(anonymous function)
http://localhost:3000/static/js/main.chunk.js:1:65

Package.json

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "antd": "^4.2.0",
    "axios": "^0.19.2",
    "formik": "^2.1.4",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-icons": "^3.10.0",
    "react-redux": "^7.2.0",
    "react-router-dom": "^5.1.2",
    "react-scripts": "3.4.1",
    "redux": "^4.0.5",
    "yup": "^0.28.5"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

我已经尝试研究了它,并且它是由 moment-js引起 的错误,但我没有使用该模块,也未安装。

可能是什么问题呢?


问题答案:

发生这种情况的原因是, 当下 已将新版本从 2.24.0发行到2.25.0

执行以下步骤来解决此问题:

步骤1: 更改版本 (在您的情况下,只需在 package.json中 的依赖项中添加 “ moment”:“
2.24.0”
,因为在 package.json 中看不到它)

"moment": "2.24.0",
"moment-timezone": "^0.5.28",

第2步: 如果您使用的是 yarn, 请在package.json文件中添加分辨率,如下所示

"dependencies" {
"moment": "2.24.0",
"moment-timezone": "^0.5.28"
},
"resolutions": {
"moment": "2.24.0"
},

有关此问题的更多信息,请访问https://github.com/moment/moment/issues/4505



 类似资料:
  • 问题内容: 我已经很长时间没有使用Node.js了,也从未使用过express。当我启动应用程序时,它刚刚返回: 启动test.html时发生错误。这是代码: 我自己的路 : 为什么呢 编辑: 这是我的新app.configure: 但它返回: 问题答案: 我假设test.html是一个静态文件。要渲染静态文件,请像这样使用静态中间件。 这告诉express在应用程序的公共目录中查找静态文件。 指

  • 我刚刚开始使用webpack,很难获得多入口点示例来构建。网页包。配置。示例中的js文件包括以下行 这对我来说是个错误 在四处搜索时,我找到了将CommonChunkPlugin与表达式一起使用的其他示例 失败并出现错误 进一步搜索发现了许多示例,包括 我的构建现在失败了 我不知道该如何进行。

  • 当运行我的项目包时,我有上面的标题错误,在我试图使用 npm安装xml2json 但是,我只有以下错误,你能给我建议或想法,从这个问题中走出来吗... 编辑:: 1 在我安装了更新的Visual Studio 2005到2012后,当我运行npm安装xml2json和npm安装xml2json--unsece-perm时,我得到下面的错误, 提前感谢,戈帕尔·R

  • 运行command:时,出现以下错误: 错误输出:module.js:339 throw err;^错误:在Function.module._resolveFileName(module.js:337:15)在Function.module._load(module.js:287:25)在module.require(module.js:366:17)在require(module.js:385:

  • 问题内容: 我的Node应用程序在本地运行良好,但是在部署到Heroku时遇到错误。该应用程序使用Sequelize在一个文件夹,其中包含,和。在本地,我可以使用中的以下代码导入模型: 这很好,但是,当我部署到Heroku时,应用程序崩溃并显示以下错误: 最初我以为是由于区分大小写(本地mac与heroku linux),但是我移动了文件,进行了git commit,然后又移回并再次提交,以确保在

  • 我的系统似乎不愿意找到mysql模块。在尝试allot之后,我仍然得到Modulenotfound错误:没有名为MySQL的模块。这是我到目前为止所做的: 1. 2. 这似乎不起作用,所以我做了以下操作: 但这似乎也不起作用。 此外,我的系统似乎找不到mysql-connector-python-rf 有什么可能出问题的猜测吗?