构建失败,使用 react-datepicker。

huangapple go评论58阅读模式
英文:

build failed using react-datepicker

问题

这是我的代码,这是一个TypeScript项目。

import React, { useState } from "react";
import ReactDatePicker from "react-datepicker";

export const DatePicker = () => {
    const [startDate, setStartDate] = useState<Date | null>(new Date());
    return (
        <ReactDatePicker
            selected={startDate}
            onChange={(date) => setStartDate(date)}
        />
    );
};

在运行构建时遇到以下错误:

ERROR in ../../node_modules/react-popper/lib/esm/index.js 2:0-34
Module not found: Error: Can't resolve './Popper' in '/Users/xx/pr/node_modules/react-popper/lib/esm'

ERROR in ../../node_modules/react-popper/lib/esm/index.js 3:0-36
Module not found: Error: Can't resolve './Manager' in '/Users/xx/pr/node_modules/react-popper/lib/esm'

ERROR in ../../node_modules/react-popper/lib/esm/index.js 4:0-40
Module not found: Error: Can't resolve './Reference' in '/Users/xx/pr/node_modules/react-popper/lib/esm'
...

react-popper 的版本是 2.3.0。我跳转到 react-popper/lib/esm/index.js 并找到了以下错误:

无法找到模块 './Popper' 的声明文件。
无法找到模块 './Manager' 的声明文件。
无法找到模块 './Reference' 的声明文件。
无法找到模块 './usePopper' 的声明文件。

有人可以帮助解决吗?

英文:

here is my code, it is a typescript procjet.

import React, { useState } from &quot;react&quot;;
import ReactDatePicker from &quot;react-datepicker&quot;;

export const DatePicker = () =&gt; {
    const [startDate, setStartDate] = useState&lt;Date | null&gt;(new Date());
    return (
      &lt;ReactDatePicker
        selected={startDate}
        onChange={(date) =&gt; setStartDate(date)}
      /&gt;
    );
};

get the error when run build

ERROR in ../../node_modules/react-popper/lib/esm/index.js 2:0-34
Module not found: Error: Can&#39;t resolve &#39;./Popper&#39; in &#39;/Users/xx/pr/node_modules/react-popper/lib/esm&#39;

ERROR in ../../node_modules/react-popper/lib/esm/index.js 3:0-36
Module not found: Error: Can&#39;t resolve &#39;./Manager&#39; in &#39;/Users/xx/pr/node_modules/react-popper/lib/esm&#39;

ERROR in ../../node_modules/react-popper/lib/esm/index.js 4:0-40
Module not found: Error: Can&#39;t resolve &#39;./Reference&#39; in &#39;/Users/xx/pr/node_modules/react-popper/lib/esm&#39;
...

the react-popper is 2.3.0.
I jump to the react-popper/lib/esm/index.js and find the error,

Could not find a declaration file for module &#39;./Popper&#39;.
Could not find a declaration file for module &#39;./Manager&#39;.
Could not find a declaration file for module &#39;./Reference&#39;. 
Could not find a declaration file for module &#39;./usePopper&#39;.

enter image description here

can anyone help on it

答案1

得分: 0

尝试清理您的 node_modules 并运行 npm run install
进行干净安装的参考:如何使用 npm 进行干净安装(删除 node_modules 并安装)

英文:

Try to clean your node_modules and run a npm run install;
References for a clean install: How do I do a clean install (delete node_modules and install) with npm

huangapple
  • 本文由 发表于 2023年6月1日 15:25:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76379559.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定