[英]Bundled script failed to load in browser
Webpack編譯成功,但無法在瀏覽器中加載。 在檢查Web控制台時,我發現_webpack_require_中無法訪問某些模塊。 當我在相關模塊中將es6 import
語法更改為require
時,在Web控制台中拋出的錯誤消失了 。 我不打算進入每個文件並更改我的import
語法為require
。 我在webpack.config.js中將.babelrc與babel-loader一起配置。
真的很困惑下一步該怎么做,因為這是我第一次使用webpack
我的webpack.config.js
***test: /\.(js|jsx)$/,
include: [
path.join(__dirname, 'client'),
path.join(__dirname, './template')
],
loader: 'babel-loader',
exclude: /node_modules/,
query: { cacheDirectory: true } ***
.babelrc文件
{
"presets": [
"es2015",
"react",
"latest",
"stage-2"
],
"plugins": [
"react-hot-loader/babel"
]
}
flashMessage.js:13未捕獲的TypeError:無法讀取對象處eval(flashMessage.js:13)處未定義的屬性'ADD_FLASH_MESSAGE'。 (bundle.js:1406)在webpack_require (bundle.js:679)在fn(bundle.js:89)在eval(index.js:9)在Object。 (bundle.js:1399)在webpack_require (bundle.js:679)在fn(bundle.js:89)在評估(index.js:9)
我要在webpack中像這樣配置babel-loader
:
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
presets: ['react'],
},
},
在完全更改了webpack.config之后,錯誤仍然存在,我發現我沒有返回用於鏡像操作數組的Array.reduce方法,因此,只要文件路徑正確,但webpack對其進行了編譯,但它未能函數返回void導致加載。 在此處找到repo link
- 只是缺少一個return關鍵字
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.