reactjs - React npm run build 失败并出现意外的 '/'

标签 reactjs

当我运行“npm start”并且一切正常且没有错误时,React 应用程序完全正常。但是当我尝试构建应用程序时,出现以下错误:

redhat-server % npm run build

> <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="abcac6dbc7c2cdd2cadbdbeb9b859a859b" rel="noreferrer noopener nofollow">[email protected]</a> build
> react-scripts build && gulp licenses

Creating an optimized production build...
Failed to compile.

static/css/main.340bdb3c.css from Css Minimizer plugin
Error: Unexpected '/'. Escaping special characters with \ may help.

我发现该错误来 self 的 index.js 文件,这是起点。我导入了这样的 CSS 文件:

import './assets/css/animate.min.css';
import "./assets/scss/light-bootstrap-dashboard-react.scss?v=2.0.0";
import "./assets/css/demo.css";

“/”是这里的问题。在每个导入路径的开头。我尝试过“.//”或“/”或“//” - 对于其中任何一个,它都会给我错误文件未找到错误

我也尝试过不使用“/”。然后它给出了这个错误。

Module not found: Error: Can't resolve 'assets/css/animate.min.css' in '/local/home/app/src'
Did you mean './assets/css/animate.min.css'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (node_modules, /local/home/app/node_modules).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.

最佳答案

这个问题也发生在我身上,我通过检查哪个css文件生成这个问题来解决它(在我的例子中是main.css),然后我发现这都是一个错误在评论中(我没有放置/**/,而是放置了**/,因此它表示“意外/”)
如果 npm buildsteal 失败,或者您找到了解决方案,请尝试此方法,与我们分享以帮助其他人。

关于reactjs - React npm run build 失败并出现意外的 '/',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70408508/

相关文章:

javascript - Electron webview 仅预加载文件 ://protocol is supported when using create-react-app base

javascript - 悬停事件的轨迹模式在 tsParticles 中不起作用(类似于 particlejs)

reactjs - this.setState 未定义

ecmascript-6 - 整个文件中可访问的常量变量

reactjs - material ui Tooltip 距 anchor 的距离

javascript - 调度操作时为 "Cannot read property ' 然后 ' of undefined"

reactjs - ES6 - 根据真值过滤对象

reactjs - 在 React 的事件处理程序上禁用 unstable_batchedUpdates()

javascript - I18N 在 Next.JS 中更改语言

javascript - 通过 setTimeOut 再次调用 setState 来响应更改状态