使用CloudFlare页面构建NPM在'找不到模块'
我正在尝试将我的Create-React-App网站上传到CloudFlare页面,但是,当我添加此行时,一切都很好:从“页面/notfound.js” import notfoundpage;
给我的app.js的代码,它引发了一个相当奇怪的错误:
22:57:43.995 Failed to compile.
22:57:43.996
22:57:43.996 ./src/App.js
22:57:43.996 Cannot find module: 'pages/NotFound.js'. Make sure this package is installed.
22:57:43.996
22:57:43.996 You can install this package by running: npm install pages/NotFound.js.
使这更令人困惑的是,它上方的代码完全可以正常工作:
import PrivacyPolicyPage from "pages/PrivacyPolicy.js";
import TermsOfUsePage from "pages/TermsOfUse.js";
import NotFoundPage from "pages/NotFound.js";
有人知道为什么会发生这种情况,最重要的是,为什么应用程序在上我的家庭环境(Windows 11)而不是Cloudflare页面?
notfound.js
的代码:
import React, { useState } from 'react';
import { Helmet } from 'react-helmet';
import ScrollToTop from 'components/ScrollToTop';
import NotFound from 'components/NotFound';
import Sidebar from 'components/Sidebar';
import Navbar from 'components/Navbar';
import Footer from 'components/Footer';
function NotFoundPage() {
const [isOpen, setIsOpen] = useState(false);
const toggle = () => {
setIsOpen(!isOpen);
};
return (
<>
<Helmet>
<link rel="stylesheet" href="/css/notfound.css" />
</Helmet>
<ScrollToTop />
<Sidebar isOpen={isOpen} toggle={toggle} />
<Navbar noFade toggle={toggle} />
<NotFound />
<Footer sticky />
</>
);
}
export default NotFoundPage;
和app.js
:
import React from "react";
import "App.css";
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
import Home from "pages";
import PrivacyPolicyPage from "pages/PrivacyPolicy.js";
import TermsOfUsePage from "pages/TermsOfUse.js";
import NotFoundPage from "pages/NotFound.js";
function App() {
return (
<Router>
<Switch>
<Route path="/" component={Home} exact />
<Route path="/privacy-policy" component={PrivacyPolicyPage} exact />
<Route path="/terms-of-use" component={TermsOfUsePage} exact />
<Route component={NotFoundPage} />
</Switch>
</Router>
);
}
export default App;
注意:我已经在./
的开始时尝试过它尝试在导入对象周围添加{}
,并且两个都没有起作用,从而丢弃了相同的错误。 npm bulderify- errorify-错误 - 无法找到模块没有找到模块帮助。
感谢任何可以提供帮助的人。
i'm trying to upload my create-react-app site to Cloudflare Pages, and everything's been going great, However, when I add this line: import NotFoundPage from "pages/NotFound.js";
of code to my App.js, it throws a rather odd error:
22:57:43.995 Failed to compile.
22:57:43.996
22:57:43.996 ./src/App.js
22:57:43.996 Cannot find module: 'pages/NotFound.js'. Make sure this package is installed.
22:57:43.996
22:57:43.996 You can install this package by running: npm install pages/NotFound.js.
What makes this even more confusing, is the code right above it works completely fine:
import PrivacyPolicyPage from "pages/PrivacyPolicy.js";
import TermsOfUsePage from "pages/TermsOfUse.js";
import NotFoundPage from "pages/NotFound.js";
Is anyone aware of why this is happening, and most importantly, why the app is building on my home environment (Windows 11) and not Cloudflare Pages?
The code of NotFound.js
:
import React, { useState } from 'react';
import { Helmet } from 'react-helmet';
import ScrollToTop from 'components/ScrollToTop';
import NotFound from 'components/NotFound';
import Sidebar from 'components/Sidebar';
import Navbar from 'components/Navbar';
import Footer from 'components/Footer';
function NotFoundPage() {
const [isOpen, setIsOpen] = useState(false);
const toggle = () => {
setIsOpen(!isOpen);
};
return (
<>
<Helmet>
<link rel="stylesheet" href="/css/notfound.css" />
</Helmet>
<ScrollToTop />
<Sidebar isOpen={isOpen} toggle={toggle} />
<Navbar noFade toggle={toggle} />
<NotFound />
<Footer sticky />
</>
);
}
export default NotFoundPage;
And App.js
:
import React from "react";
import "App.css";
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
import Home from "pages";
import PrivacyPolicyPage from "pages/PrivacyPolicy.js";
import TermsOfUsePage from "pages/TermsOfUse.js";
import NotFoundPage from "pages/NotFound.js";
function App() {
return (
<Router>
<Switch>
<Route path="/" component={Home} exact />
<Route path="/privacy-policy" component={PrivacyPolicyPage} exact />
<Route path="/terms-of-use" component={TermsOfUsePage} exact />
<Route component={NotFoundPage} />
</Switch>
</Router>
);
}
export default App;
NOTE: I have tried it with ./
at the start of the import string, tried adding {}
around the import object, and neither of those work either, throwing the same error. npm build with Browserify - Error: Cannot find module did not help.
Thank you to anyone who can help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我设法通过(并且知道这听起来很奇怪)将问题重命名为
pages
目录到page
。我的猜测是,Cloudflare正在做一些奇怪的事情,但我真的不确定。I managed to fix the issue by (and I know how odd this sounds) renaming the
pages
directory topage
. My guess is that Cloudflare is doing some weird stuff with that, but I can't really be sure.