简体   繁体   English

找不到模块:无法在 reactjs 中解析 'node_modules\react-moment\dist' 中的 'moment'

[英]Module not found: Can't resolve 'moment' in 'node_modules\react-moment\dist' in reactjs

I have installed react-moment 'npm i react-moment'.我已经安装了 react-moment 'npm i react-moment'。 It is installed in the directory node_modules and dependency added in the package.json file.安装在node_modules目录下,依赖添加在package.json文件中。 Every thing is correct.每件事都是正确的。 But when I import但是当我导入

import Moment from 'react-moment'

then it shows然后它显示

Module not found: Can't resolve 'moment' in 'node_modules\react-moment\dist'

But there is nothing wrong with this directory, I haven't modified the files inside react-moment directory in node_modules.但是这个目录没有任何问题,我没有修改node_modules中react-moment目录里面的文件。 Just after installing the package, when I import the package在安装 package 之后,当我导入 package 时

import Moment from 'react-moment'

Then it shows the error.然后它显示错误。

moment is a peer dependency of react-moment , which mean you have to install moment in you project as well (it doesn't ship with its own version of moment ). momentreact-moment对等依赖项,这意味着您还必须在项目中安装moment (它不附带自己的moment版本)。

npm i --save moment

I sorted it out by adding the '--legacy-peer-deps' argument to the end of the command as the error message shows:我通过在命令末尾添加“--legacy-peer-deps”参数来解决这个问题,如错误消息所示:

 npm ERR: Conflicting peer dependency. @angular/common@13.3.12 npm ERR. node_modules/@angular/common npm ERR. peer @angular/common@">=13.0.0 <14.0.0" from @ng-select/ng-select@8.3.0 npm ERR. node_modules/@ng-select/ng-select npm ERR. @ng-select/ng-select@"^8.0.0" from @ng-matero/extensions@13.1,0 npm ERR, node_modules/@ng-matero/extensions npm ERR. @ng-matero/extensions@"^13.1.0" from the root project npm ERR. @ng-select/ng-select@"^8:1.1" from the root project npm ERR. npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! See /Users/yimin/.npm/eresolve-report.txt for a full report. npm ERR! A complete log of this run can be found in: npm ERR! /Users/yimin/.npm/_logs/2022-12-01T14_08_17_585Z-debug-0.log
 npm install --save moment --legacy-peer-deps

Worked for me:为我工作:

  1. npm install --save moment
  2. npm install --save react-moment
  3. npm install --save moment-timezone

:) :)

I was having same issue with reac-datetime package and this one worked for me:我在使用 reac -datetime package 时遇到了同样的问题,这个问题对我有用:

npm install --save moment

If you are working with Timezone features make sure that you have installed the timezone package as well.如果您正在使用时区功能,请确保您也安装了时区 package。 if not paste the below npm code.如果不粘贴下面的 npm 代码。

npm install --save moment-timezone npm install --save moment-timezone

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 引导反应。/node_modules/bootstrap/dist/js/bootstrap.min.js 找不到模块:无法解析“jquery” - Bootstrap react ./node_modules/bootstrap/dist/js/bootstrap.min.js Module not found: Can't resolve 'jquery' 找不到模块:无法解析“C:\react-test\src\components\content”中的“node_modules/react” - Module not found: Can't resolve 'node_modules/react' in 'C:\react-test\src\components\content' 未找到模块:无法解析“E:\frontend\node_modules\@mui\styled-engine”中的“@emotion/react” - Module not found: Can't resolve '@emotion/react' in 'E:\frontend\node_modules\@mui\styled-engine' MUI:找不到模块“找不到模块:错误:无法解析&#39;时刻&#39;” - MUI : Module not found "Module not found: Error: Can't resolve 'moment' " 找不到模块:无法解析&#39;\\ node_modules \\ react-addons-perf&#39;中的&#39;react-dom / lib / ReactPerf&#39; - Module not found: Can't resolve 'react-dom/lib/ReactPerf' in '\node_modules\react-addons-perf' 编译失败。 ./node_modules/react-dev-utils/formatWebpackMessages.js 模块未找到:无法解析 - Failed to compile. ./node_modules/react-dev-utils/formatWebpackMessages.js Module not found: Can't resolve 找不到模块:错误:无法在“/Users/”中解析“./node_modules/react”<user-name> /Documents/gift-test/client'</user-name> - Module not found: Error: Can't resolve './node_modules/react' in '/Users/<user-name>/Documents/gift-test/client' 找不到模块:无法解析“/Users/Austin/node_modules/pg/lib”中的“dns” - Module not found: Can't resolve 'dns' in '/Users/Austin/node_modules/pg/lib' 找不到模块:无法解析“./node_modules/@material-ui/core/IconButton” - Module not found: Can't resolve './node_modules/@material-ui/core/IconButton' react-moment fromnownow功能在javascript中? - react-moment fromnow ago function in javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM