首页 文章

捆绑的脚本无法在浏览器中加载

提问于
浏览
0

Webpack编译成功但无法在浏览器中加载 . 在检查Web控制台时,我发现无法在_webpack_require_中访问某些模块 . When I changed the es6 import syntax to require in the concerned module, the error thrown in the web console goes away . 我不打算进入每个文件并将 import 语法更改为 require . 我的.babelrc与我的webpack.config.js中的babel-loader一起配置 .

真的很困惑下一步做什么,因为这是我第一次使用webpack

My 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 file

{
  "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)at webpack_require(bundle.js:679)at fn(bundle.js:89)at eval(index.js:9)at Object . (bundle.js:1399)at webpack_require(bundle.js:679)at fn(bundle.js:89)at eval(index.js:9)

2 回答

  • 0

    我在webpack中这样配置 babel-loader 如下:

    test: /\.(js|jsx)$/,
            exclude: /node_modules/,
            use: {
              loader: 'babel-loader',
              options: {
                cacheDirectory: true,
                presets: ['react'],
              },
            },
    
  • 0

    我完全改变了我的webpack.config后错误仍然存在,我发现我没有返回Array.reduce方法,该方法是为了镜像一系列操作,所以webpack编译它只要文件路径是正确的但它没有由于函数返回void而导致的负载 . 找到 repo link here - Just a missing return keyword

相关问题