webpack react 錯誤整理

來源:互聯網
上載者:User

標籤:開啟   plugin   app   about   develop   技術   amp   pac   tar   

1、ERROR in ./src/entry.js

Module build failed: SyntaxError

解決方案:

安裝babel-preset-react,  npm install --save-dev babel-preset-react

 

修改webpack設定檔,添加preset選項

 

2、ERROR in bundle.js from UglifyJs

Unexpected token: punc ()) [bundle.js:25884,14]

在添加並使用react-router-dom後,編譯報錯

解決方案:安裝babel-preset-es2015 ,然後配置.babelrc檔案

具體用法查看:https://babeljs.io/docs/plugins/preset-es2015/

 

3、Warning: It looks like you‘re using a minified copy of the development build of React.

When deploying React apps to production, make sure to use the production build which skips development warnings and is faster. See https://fb.me/react-minification for more details.

根據 https://reacttraining.com/react-router/web/example/basic給出的例子,編譯沒報錯,頁面開啟時,控制台出現警告,點選連結時報錯

 Uncaught DOMException: Failed to execute ‘pushState‘ on ‘History‘: A history state object with URL ‘file:///E:/about‘ cannot be created in a document with origin ‘null‘ and URL

解決警告方法:修改webpack設定檔,添加如下內容

網上暫時沒找到直接的解決方案,只能一步步尋找原因,將Route上的exact去掉後,發現頁面可以顯示Home內容,所以路由是沒問題的,問題在Link上面

關於Route exact,官方文檔給出的說明如下,看了之後還是沒太明白o(╯□╰)o,大致理解就是不加exact,預設首頁顯示patch為“/”的頁面,加了之後exact後,匹配路徑時要求更嚴格一些

 4、使用箭頭函數時編譯報錯

解決方案:安裝babel-preset-stage-1

npm install babel-preset-stage-1  --save-dev

修改設定檔,添加stage-1選項

 參考:http://blog.csdn.net/wq_static/article/details/51330780

 

5、cannot read push of undefined

使用this.context.router.push("about")進行頁面跳轉時報錯

解決方案:添加如下內容

 

6、Uncaught TypeError: n.context.router.push is not a function

使用版本如下:

解決方案:

將 this.context.router.push("about") 換成

this.context.router.history.push("about")

參考:this-context-router-push-is-not-a-function

 

webpack react 錯誤整理

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.