简体   繁体   English

无法生成 webapp 的构建版本

[英]Cannot produce built version of webapp

When I try to run 'npm run build' it gives me a parse error but does not specify where the problem is.当我尝试运行“npm run build”时,它给了我一个解析错误,但没有指定问题出在哪里。

Error: Parse Error: <div id={"headerBar"}>
        <h1>My Todo Webapp</h1>        
      </div>
      <div id="root"></div>                 
      <div id={"footerBar"}>                
        <h1>View Source Code</h1>           
      </div>
    <script>!function(e){function r(r){for(var n,f,i=r[0],l=r[1],a=r[2],c=0,s=[];c<i.length;c++)f=i[c],o[f]&&s.push(o[f][0]),o[f]=0;for(n in l)Object.prototype.hasOwnProperty.call(l,n)&&(e[n]=l[n]);for(p&&p(r);s.length;)s.shift()();
  return u.push.apply(u,a||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,i=1;i<t.length;i++){var l=t[i];0!==o[l]&&(n=!1)}n&&(u.splice(r--,1),e=f(f.s=t[0]))}return e}var n={},o={2:0},u=[];function f(r){if(n[r
  ])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.m=e,f.c=n,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefin
  ed"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,r){if(1&r&&(e=f(e)),8&r)return e;if(4&r&&"object"===typeof e&&e
  &&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)f.d(t,n,function(r){return e[r]}.bind(null,n));return t},f.n=function(e)
  {var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var i=window.webpackJsonp=window.webpackJsonp||[],l=i.push
  .bind(i);i.push=r,i=i.slice();for(var a=0;a<i.length;a++)r(i[a]);var p=l;t()}([]);
  //# sourceMappingURL=runtime~main.229c360f.js.map</script><script src="/static/js/1.682b0dce.chunk.js"></script><script src="/static/js/main.afbb6237.chunk.js"></script></body>
  </html>

It also shows these messages at the bottom, I presume a stack trace of some kind but I don't know where to find the problem:它还在底部显示这些消息,我推测某种堆栈跟踪,但我不知道在哪里找到问题:

- htmlparser.js:240 new HTMLParser
    [react-practice]/[html-minifier]/src/htmlparser.js:240:13

  - htmlminifier.js:966 minify
    [react-practice]/[html-minifier]/src/htmlminifier.js:966:3

  - htmlminifier.js:1326 Object.exports.minify
    [react-practice]/[html-minifier]/src/htmlminifier.js:1326:16

  - index.js:411 HtmlWebpackPlugin.postProcessHtml
    [react-practice]/[html-webpack-plugin]/index.js:411:34

  - index.js:246
    [react-practice]/[html-webpack-plugin]/index.js:246:27

However, it does produce a build that has the correct functionality, except it does not have any of my imported CSS, so I assume that is the problem.但是,它确实生成了具有正确功能的构建,除了它没有任何我导入的 CSS,所以我认为这是问题所在。 To use CSS all I have done is要使用 CSS 我所做的就是

import './Styles.css' (I have also tried with require("./Styles.css') and with removing all the stylesheets) import './Styles.css' (我也尝试过使用 require("./Styles.css') 并删除所有样式表)

It worked fine when I was developing using "npm start".当我使用“npm start”进行开发时,它运行良好。 Any help would be appreciated!任何帮助,将不胜感激!

It still gives a "parse error" when I remove all the CSS (and imports) from my files, and it still produces an index.html that I can load which is functional, but with no styling whatsoever (obviously because I have deleted all my CSS, but it still gives a build error)当我从我的文件中删除所有 CSS (和导入)时,它仍然会给出“解析错误”,并且它仍然会产生一个 index.html 我可以加载它是功能性的,但没有任何样式(显然是因为我已经删除了所有我的 CSS,但它仍然给出构建错误)

I am only using the default configuration created with webstorm to create a react application.我只使用使用 webstorm 创建的默认配置来创建反应应用程序。

My problem was that my index.html included a header and footer div above and below my root div for react.我的问题是我的 index.html 在我的根 div 上方和下方包含一个 header 和页脚 div 以进行反应。 I have refactored it so the header and footer are created in my App.js.我已经对其进行了重构,因此在我的 App.js 中创建了 header 和页脚。 I have no idea why I need to do this but it works now.我不知道为什么我需要这样做,但它现在有效。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM