简体   繁体   English

无法读取未定义的Webpack Bootstrap React的属性“调用”

[英]Cannot read property 'call' of undefined Webpack Bootstrap React

I'm having an issue that I have found others too have had. 我遇到了一个发现其他人也遇到过的问题。 The only problem I am running into is that all solutions I have found do not seem to work for me. 我遇到的唯一问题是,我发现的所有解决方案似乎都不适合我。 When I build my project everything succeeds without error. 当我构建项目时,一切都会成功而没有错误。 I then start webpack-dev-server on my built project within my dist folder. 然后,我在dist文件夹中的已建项目中启动webpack-dev-server When I open the browser I receive the following error: 当我打开浏览器时,出现以下错误: 开发工具错误日志

Now this does not occur when I am running webpack-dev-server in development mode. 现在,当我在开发模式下运行webpack-dev-server时,这不会发生。 The simple explanation is because I am not performing any code splitting in my webpack.config.dev.js file. 简单的解释是因为我没有在webpack.config.dev.js文件中执行任何代码拆分。 So I know the problem is occurring with my CommonsChunkPlugin . 所以我知道我的CommonsChunkPlugin出现了问题。 I just cannot nail down exactly why. 我无法确切说明原因。 Here is the link to the repo that I am working on: Nappstir/react-landing-page . 这是我正在处理的仓库的链接: Nappstir / react-landing-page There is nothing complex about this project. 这个项目没有什么复杂的。 I am simply trying to build a template for basic landing pages that will be built in React , thus no Redux is wired. 我只是在尝试为将在React构建的基本登录页面构建模板,因此没有连接Redux Any ideas on what could be causing this error? 关于什么可能导致此错误的任何想法?

You can clone this project and simply run npm install and npm run build to build the project. 您可以克隆该项目,只需运行npm installnpm run build即可构建项目。 Then just visit ' http://localhost:3000/ ` 然后只需访问' http:// localhost:3000 / `

I actually found the reasoning as to why this error was occurring. 实际上,我找到了发生此错误的原因。 It appears the issue had to do with the file order that my html-webpack-plugin was injecting the files. 看来问题与我的html-webpack-plugin注入文件的文件顺序有关。 What was done to resolve this was use the chunks & chunksSortMode properties provided by html-webpack-plugin . 解决此问题的方法是使用html-webpack-plugin提供的chunkschunksSortMode属性。 The code would look something like this: 代码看起来像这样:

chunks: ['manifest', 'vendor', 'main'],
chunksSortMode: function (a, b) {
  let orders = ['manifest', 'vendor', 'main'];
  if (orders.indexOf(a.names[0]) > orders.indexOf(b.names[0])) {
    return 1;
  } else if (orders.indexOf(a.names[0]) < orders.indexOf(b.names[0])) {
    return -1;
  } else {
    return 0;
  }
},

This then returns each chunk in specified order of your chunks array. 然后,这chunks数组的指定顺序返回每个块。

chunks: ['manifest', 'vendor', 'main'],
chunksSortMode: function (a, b) {
 const orders = ['manifest', 'vendor', 'main'];
 return orders.indexOf(a.names[0]) - orders.indexOf(b.names[0]);
}

according to @Nappstir, this will be better 根据@Nappstir,这会更好

I solved the problem upgrading to Babel 7 https://babeljs.io/docs/en/v7-migration . 我解决了升级到Babel 7的问题https://babeljs.io/docs/en/v7-migration Using command npx babel-upgrade 使用命令npx babel-upgrade

暂无
暂无

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

相关问题 无法读取未定义的属性“ engine”-Webpack React - Cannot read property 'engine' of undefined - Webpack React 使用webpack进行反应,“ bootstrap.bundle.js无法读取未定义的属性&#39;setAttribute&#39;”-Popper - React with webpack, “bootstrap.bundle.js Cannot read property 'setAttribute' of undefined” - popper Webpack 4 + bootstrap [TypeError: Cannot read property 'jquery' of undefined] - Webpack 4 + bootstrap [TypeError: Cannot read property 'jquery' of undefined] 反应 - 无法读取未定义的属性“调用” - React - Cannot read property 'call' of undefined 反应超级,无法读取未定义的属性“调用” - react super, Cannot read property 'call' of undefined Webpack Uncaught TypeError:无法读取未定义的属性“调用” - Webpack Uncaught TypeError: Cannot read property 'call' of undefined 未捕获的类型错误:无法读取 __webpack_require__ 处未定义的属性“调用” - Uncaught TypeError: Cannot read property 'call' of undefined at __webpack_require__ 无法从 webpackAsyncContext 读取未定义的属性“调用”(Webpack 错误) - Cannot read property 'call' of undefined from webpackAsyncContext (Webpack error) React / Webpack / Django-未捕获的TypeError:无法读取未定义的属性“ XXX” - React/Webpack/Django - Uncaught TypeError: Cannot read property 'XXX' of undefined 无法读取未定义的属性“组件”-react 组件插件的 webpack 构建 - Cannot read property 'Component' of undefined - webpack build of react component plugin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM